mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 21:10:38 +03:00
23 lines
625 B
TypeScript
23 lines
625 B
TypeScript
![]() |
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||
|
|
||
|
import { authApi } from './api';
|
||
|
|
||
|
export const useLogin = () => {
|
||
|
const client = useQueryClient();
|
||
|
const mutation = useMutation({
|
||
|
mutationKey: ['login'],
|
||
|
mutationFn: authApi.login,
|
||
|
onSettled: async () => await client.invalidateQueries({ queryKey: [authApi.baseKey] })
|
||
|
});
|
||
|
return {
|
||
|
login: (
|
||
|
username: string, //
|
||
|
password: string,
|
||
|
onSuccess?: () => void
|
||
|
) => mutation.mutate({ username, password }, { onSuccess }),
|
||
|
isPending: mutation.isPending,
|
||
|
error: mutation.error,
|
||
|
reset: mutation.reset
|
||
|
};
|
||
|
};
|