48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
import { authFetch } from "../../../utils/authFetch";
|
|
import { log } from "../../../utils/logger";
|
|
|
|
export async function fetchUserStatusApi() {
|
|
log("fetchUserStatusApi called");
|
|
const res = await authFetch(
|
|
`${import.meta.env.VITE_API_BASE_URL}/api/auth/user/status`,
|
|
{ method: "GET", credentials: "include" }
|
|
);
|
|
if (!res.ok) {
|
|
log("fetchUserStatusApi failed with status:", res.status);
|
|
throw new Error("Failed to fetch user status");
|
|
}
|
|
const json = await res.json();
|
|
log("fetchUserStatusApi success, response:", json);
|
|
return json;
|
|
}
|
|
|
|
export async function fetchUserApi() {
|
|
log("fetchUserApi called");
|
|
const res = await authFetch(
|
|
`${import.meta.env.VITE_API_BASE_URL}/api/auth/me`,
|
|
{ method: "GET", credentials: "include" }
|
|
);
|
|
if (!res.ok) {
|
|
log("fetchUserApi failed with status:", res.status);
|
|
throw new Error("Failed to fetch user");
|
|
}
|
|
const json = await res.json();
|
|
log("fetchUserApi success, response:", json);
|
|
return json;
|
|
}
|
|
|
|
export async function refreshTokenApi() {
|
|
log("refreshTokenApi called");
|
|
const res = await fetch(
|
|
`${import.meta.env.VITE_API_BASE_URL}/api/auth/refresh`,
|
|
{ method: "POST", credentials: "include" }
|
|
);
|
|
if (!res.ok) {
|
|
log("refreshTokenApi failed with status:", res.status);
|
|
throw new Error("Failed to refresh token");
|
|
}
|
|
const json = await res.json();
|
|
log("refreshTokenApi success, response:", json);
|
|
return json;
|
|
}
|