-
Notifications
You must be signed in to change notification settings - Fork 1.9k
chore(ui): ensure token updated before making failed req #27140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,8 +87,8 @@ class TokenService { | |
| this.setRefreshInProgress(); | ||
|
|
||
| try { | ||
| const token = await getOidcToken(); | ||
| const { isExpired, timeoutExpiry } = extractDetailsFromToken(token); | ||
| const oldToken = await getOidcToken(); | ||
| const { isExpired, timeoutExpiry } = extractDetailsFromToken(oldToken); | ||
|
|
||
| // If token is expired or timeoutExpiry is less than 0 then try to silent signIn | ||
| if (isExpired || timeoutExpiry <= 0) { | ||
|
|
@@ -160,6 +160,21 @@ class TokenService { | |
| isTokenUpdateInProgress() { | ||
| return localStorage.getItem(REFRESH_IN_PROGRESS_KEY) === 'true'; | ||
| } | ||
|
|
||
| private async waitForTokenPersistence(oldToken: string) { | ||
| const maxAttempts = 20; | ||
| const delayMs = 50; | ||
|
|
||
| for (let attempt = 0; attempt < maxAttempts; attempt++) { | ||
| await new Promise((resolve) => setTimeout(resolve, delayMs)); | ||
|
|
||
| const currentToken = await getOidcToken(); | ||
|
|
||
| if (currentToken && currentToken !== oldToken) { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+164
to
+177
|
||
| } | ||
|
|
||
| export default TokenService; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The retry path treats a falsy
refreshToken()result as a refresh failure (resetUserDetails(true)), but some authenticators intentionally returnvoidfor silent refresh (e.g., OidcAuthenticator’srenewIdTokenresolves with no token and persists it via the silent-callback). In those cases this branch will force-logout and will never retry queued requests even though the token may have been refreshed. Consider basing the decision to retry on the persisted token (e.g., re-readgetOidcToken()/ compare against the previous token) or adjustTokenService.refreshToken()to resolve with the persisted token once it’s available.