fix(mcp): восстановить вход после отзыва доступа
This commit is contained in:
1 parent
54f3d19afb
commit
cbc59ef850
6 files changed
+250
-20
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user