Files
django-vue3-admin-gd/web/apps/web-antd/src/utils/fetch-with-auth.ts
2025-07-21 22:22:32 +08:00

15 lines
518 B
TypeScript

import { useAccessStore } from '@vben/stores';
import { formatToken } from '#/utils/auth';
export const API_BASE = '/api/ai/v1/';
export function fetchWithAuth(input: RequestInfo, init: RequestInit = {}) {
const accessStore = useAccessStore();
const token = accessStore.accessToken;
const headers = new Headers(init.headers || {});
headers.append('Content-Type', 'application/json');
headers.append('Authorization', formatToken(token) as string);
return fetch(API_BASE + input, { ...init, headers });
}