MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / handleOAuth401ErrorImpl

Function handleOAuth401ErrorImpl

src/utils/auth.ts:1369–1388  ·  view source on GitHub ↗
(
  failedAccessToken: string,
)

Source from the content-addressed store, hash-verified

1367}
1368
1369async function handleOAuth401ErrorImpl(
1370 failedAccessToken: string,
1371): Promise<boolean> {
1372 // Clear caches and re-read from keychain (async — sync read blocks ~100ms/call)
1373 clearOAuthTokenCache()
1374 const currentTokens = await getClaudeAIOAuthTokensAsync()
1375
1376 if (!currentTokens?.refreshToken) {
1377 return false
1378 }
1379
1380 // If keychain has a different token, another tab already refreshed - use it
1381 if (currentTokens.accessToken !== failedAccessToken) {
1382 logEvent('tengu_oauth_401_recovered_from_keychain', {})
1383 return true
1384 }
1385
1386 // Same token that failed - force refresh, bypassing local expiration check
1387 return checkAndRefreshOAuthTokenIfNeeded(0, true)
1388}
1389
1390/**
1391 * Reads OAuth tokens asynchronously, avoiding blocking keychain reads.

Callers 1

handleOAuth401ErrorFunction · 0.85

Calls 4

clearOAuthTokenCacheFunction · 0.85
logEventFunction · 0.85

Tested by

no test coverage detected