Files
The_DisExcel_project/frontend/src/api/token.ts
T

18 lines
525 B
TypeScript

export const API_URL = import.meta.env.VITE_BACKEND_URL;
let accessToken: string | null = null;
export function setAccessToken(token: string | null) {
accessToken = token;
}
export function getAccessToken() {
return accessToken;
}
export async function authFetch(path: string, init: RequestInit = {}) {
const headers = new Headers(init.headers);
if (accessToken) headers.set("Authorization", `Bearer ${accessToken}`);
return fetch(`${API_URL}${path}`, { ...init, headers, credentials: "include" });
}