Files
blog/write-server/src/lib/fetch.ts
T

9 lines
329 B
TypeScript
Raw Normal View History

2026-06-22 15:55:09 +08:00
// 带认证的 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 });
}