mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
23 lines
613 B
TypeScript
23 lines
613 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: () => 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
|
|
};
|
|
};
|