fix(mcp): восстановить вход после отзыва доступа

This commit is contained in:
Denozordec committed 2026-11-15 17:54:34 +07:00
1 parent 54f3d19afb
commit cbc59ef850
6 files changed
+250 -20

No files matched your search

+11 -5
View File
@@ -49,10 +49,16 @@ export function withAuthHeaders(init?: HeadersInit): Headers {
return headers
}
function handleUnauthorized(): never {
let portalHandoffStarted = false
function handleUnauthorized(authorization: string | null): never {
if (typeof window !== "undefined" && isAuthEnabled()) {
const ok = redirectToPortalLogin()
if (!ok) redirectToPortalLoginInteractive()
const token = getToken()
if (!portalHandoffStarted && (!token || authorization === `Bearer ${token}`)) {
const ok = redirectToPortalLogin()
if (!ok) redirectToPortalLoginInteractive()
portalHandoffStarted = true
}
}
throw new ApiClientError("Unauthorized", 401)
}
@@ -86,7 +92,7 @@ export async function requestJson<T>(
headers,
})
if (res.status === 401) handleUnauthorized()
if (res.status === 401) handleUnauthorized(headers.get("Authorization"))
if (res.status === 204) return undefined as T
@@ -116,7 +122,7 @@ export async function requestBlob(
...init,
headers,
})
if (res.status === 401) handleUnauthorized()
if (res.status === 401) handleUnauthorized(headers.get("Authorization"))
if (!res.ok) {
throw new ApiClientError(await parseErrorMessage(res), res.status)
}