fix(frontend): update AuthContext user + isAuthenticated on silent token refresh (#560)#600
Merged
feyishola merged 2 commits intoJun 29, 2026
Conversation
…ken refresh (Servora#560) The token-refresh interceptor in endpoints.ts wrote the new access token to tokenStorage and called notifyTokenRefreshed, but AuthContext's callback only ran setIsLoading(false) (a no-op when already loaded). Because isAuthenticated was derived by reading tokenStorage directly during render, nothing re-rendered after a background refresh, so consumers kept seeing stale/false auth state until the next 5-minute expiry check. - AuthContext: track the access token in React state (`accessToken`) and derive isAuthenticated from it, so it is reactive. The refresh callback now updates the reactive token (and the user, when the refresh response carries one) and re-renders consumers immediately. login/clearAuth/expiry-check keep the reactive token in sync; the callback is torn down on unmount. - tokens.ts: TokenRefreshCallback now forwards an optional `user`. - endpoints.ts: pass refreshResponse.user to notifyTokenRefreshed so the user object is refreshed too, not just the token. Tests: AuthContext.test.tsx (4 cases) — refresh flips isAuthenticated to true and sets the user; user object updates from the refresh; expired refreshed token is ignored. All pass; tsc --noEmit clean on the changed files. NOTE: `npm run build` is pre-existing-broken on main due to an unresolved merge conflict marker in src/pages/Verify.tsx (line 1 `<<`), unrelated to this change.
|
@Cybermaxi7 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
@Cybermaxi7 pls resolve conflicts |
feyishola
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #560\
The token-refresh interceptor in endpoints.ts wrote the new access token to tokenStorage and called notifyTokenRefreshed, but AuthContext's callback only ran setIsLoading(false) (a no-op when already loaded). Because isAuthenticated was derived by reading tokenStorage directly during render, nothing re-rendered after a background refresh, so consumers kept seeing stale/false auth state until the next 5-minute expiry check.
accessToken) and derive isAuthenticated from it, so it is reactive. The refresh callback now updates the reactive token (and the user, when the refresh response carries one) and re-renders consumers immediately. login/clearAuth/expiry-check keep the reactive token in sync; the callback is torn down on unmount.user.Tests: AuthContext.test.tsx (4 cases) — refresh flips isAuthenticated to true and sets the user; user object updates from the refresh; expired refreshed token is ignored. All pass; tsc --noEmit clean on the changed files.
NOTE:
npm run buildis pre-existing-broken on main due to an unresolved merge conflict marker in src/pages/Verify.tsx (line 1<<), unrelated to this change.