mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
fix(web): exclude /api/session/* from 401 auto-refresh to prevent re-entrancy
This commit is contained in:
1 parent
7509814abc
commit
e2e888710a
1 file changed
+3
-3
+3
-3
@@ -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/');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user