fix(web): exclude /api/session/* from 401 auto-refresh to prevent re-entrancy

This commit is contained in:
saopig1 committed 2026-05-27 13:56:14 +08:00
1 parent 7509814abc
commit e2e888710a
1 file changed
+3 -3
+3 -3
View File
@@ -15,7 +15,7 @@ export function apiFetch(input: RequestInfo | URL, init: RequestInit = {}): Prom
headers: { ...(init.headers ?? {}) }, headers: { ...(init.headers ?? {}) },
}; };
return fetch(input, merged).then(async (res) => { return fetch(input, merged).then(async (res) => {
if (res.status === 401 && isApiPath(input)) { if (res.status === 401 && shouldTriggerRefresh(input)) {
const session = useSession(); const session = useSession();
await session.refresh(); await session.refresh();
const current = router.currentRoute.value; const current = router.currentRoute.value;
@@ -27,9 +27,9 @@ export function apiFetch(input: RequestInfo | URL, init: RequestInit = {}): Prom
}); });
} }
function isApiPath(input: RequestInfo | URL): boolean { function shouldTriggerRefresh(input: RequestInfo | URL): boolean {
const url = typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url; const url = typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url;
return url.startsWith('/api/'); return url.startsWith('/api/') && !url.startsWith('/api/session/');
} }
/** /**