diff --git a/web/src/api/profile.ts b/web/src/api/profile.ts new file mode 100644 index 0000000..2bd2608 --- /dev/null +++ b/web/src/api/profile.ts @@ -0,0 +1,29 @@ +import { handleApiError } from "."; + +export interface FetchProfileResponse { + full_name: string; + email: string; + phone_number: string; + isAdmin: boolean; + last_login: string; + profile_picture: string | null; + updated_at: string; + created_at: string; +} + +export const fetchProfileApi = async (accessToken: string) => { + const response = await fetch("/api/v1/oauth/code", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${accessToken}`, + }, + }); + + if (response.status !== 200 && response.status !== 201) + throw await handleApiError(response); + + const data: FetchProfileResponse = await response.json(); + + return data; +};