| 1 | import { api } from "@/lib/api"; |
| 2 | import { useQuery } from "@tanstack/react-query"; |
| 3 | |
| 4 | export const useCurrentUser = () => { |
| 5 | const { |
| 6 | isLoading, |
| 7 | isError, |
| 8 | data: user, |
| 9 | } = useQuery({ |
| 10 | queryKey: ["currentUser"], |
| 11 | queryFn: async () => { |
| 12 | try { |
| 13 | const response = await api.get("/auth/current-user"); |
| 14 | return response.data; |
| 15 | } catch (error) { |
| 16 | console.error(error); |
| 17 | return null; |
| 18 | } |
| 19 | }, |
| 20 | }); |
| 21 | |
| 22 | return { isLoading, isError, user }; |
| 23 | }; |