[优化] 更新认证机制,使用 OPENFLARE_TOKEN 替代 Bearer Token

This commit is contained in:
ryan
2026-06-04 11:10:06 +08:00
parent bdc96f6d8e
commit 6aa71a4da8
38 changed files with 462 additions and 387 deletions
+7
View File
@@ -1,4 +1,5 @@
import { publicEnv } from '@/lib/env/public-env';
import { getStoredOpenFlareToken } from '@/lib/api/auth-token';
import type { ApiEnvelope } from '@/types/api';
export class ApiError extends Error {
@@ -23,6 +24,12 @@ export async function apiRequest<T>(path: string, init?: RequestInit) {
if (!(init?.body instanceof FormData) && !headers.has('Content-Type')) {
headers.set('Content-Type', 'application/json');
}
if (!headers.has('OPENFLARE_TOKEN')) {
const token = getStoredOpenFlareToken();
if (token) {
headers.set('OPENFLARE_TOKEN', token);
}
}
const response = await fetch(getApiUrl(path), {
credentials: 'include',