first commit
This commit is contained in:
22
frontend/src/hooks/useAuth.ts
Normal file
22
frontend/src/hooks/useAuth.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import * as authApi from '../api/auth';
|
||||
import { useAuthStore } from '../stores/authStore';
|
||||
|
||||
export function useLogin() {
|
||||
const storeLogin = useAuthStore((s) => s.login);
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ username, password }: { username: string; password: string }) =>
|
||||
authApi.login(username, password),
|
||||
onSuccess: (data) => {
|
||||
storeLogin(data.access_token);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useRegister() {
|
||||
return useMutation({
|
||||
mutationFn: ({ username, password }: { username: string; password: string }) =>
|
||||
authApi.register(username, password),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user