Files
blog/write-server/src/lib/fetch.ts
T
2026-06-22 15:55:09 +08:00

10 lines
329 B
TypeScript

// 带认证的 fetch 封装
export async function authFetch(url: string, options: RequestInit = {}): Promise<Response> {
const token = localStorage.getItem("wauth_token");
const headers = new Headers(options.headers);
if (token) {
headers.set("X-Auth-User", token);
}
return fetch(url, { ...options, headers });
}