initial commit

This commit is contained in:
2026-03-12 06:37:16 +08:00
commit c31ebd35e7
41 changed files with 6272 additions and 0 deletions

26
src/api/client.ts Normal file
View File

@@ -0,0 +1,26 @@
import { API_BASE_URL } from "../config/constants";
export const authFetch = async (endpoint: string, options: RequestInit = {}) => {
const token = localStorage.getItem("accessToken");
const isFormData = options.body instanceof FormData;
const headers: HeadersInit = {
...(!isFormData && { "Content-Type": "application/json" }),
...(token ? { Authorization: `Bearer ${token}` } : {}),
...options.headers,
};
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
...options,
headers,
});
if (response.status === 401) {
localStorage.removeItem("accessToken");
localStorage.removeItem("refreshToken");
window.location.href = "/login";
}
return response;
};