Files
Plataforma-de-Tutoriais/frontend-plataforma-tutoriais/src/hooks/useGetCurrentUser.ts
2026-05-28 14:41:32 +01:00

27 lines
719 B
TypeScript

import API_URL from "../config/api";
import type { User } from "../types";
interface ApiUserResponse {
message: string;
data: User;
errors: null | unknown;
}
export function useGetCurrentUser() {
async function getCurrentUser(): Promise<ApiUserResponse> {
const response = await fetch(`${API_URL}/api/me`, {
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${localStorage.getItem("token")}`
},
});
const currentUser = await response.json() as ApiUserResponse;
return currentUser;
}
return { getCurrentUser };
}