| import { useState, useEffect } from 'react'; |
| import { useMutation } from '@tanstack/react-query'; |
| import { login } from './authApi'; |
| import { LoginRequest } from './types'; |
|
|
| export const useAuth = () => { |
|
|
| const loginMutation = useMutation({ |
| mutationFn: (data: LoginRequest) => login(data), |
| onSuccess: (data) => { |
| console.log(data) |
| return data; |
| }, |
| onError: (error) => { |
| console.error('Login Error:', error); |
| }, |
| }); |
|
|
| return { |
| login: loginMutation.mutateAsync, |
| isLoading: loginMutation.isPending, |
| error: loginMutation.error, |
| }; |
| }; |