fix(auth): eliminate redirect loops in ensureAuthBootstrapped#878
Open
Copilot wants to merge 3 commits into
Open
fix(auth): eliminate redirect loops in ensureAuthBootstrapped#878Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Add REDIRECT_GUARD_TTL_MS (10 s) constant for time-bound guard expiry - Track redirectUserGuardSetAt timestamp when guard is armed - Unsubscribe previous onAuthStateChanged listener before attaching a new one, preventing listener accumulation on HMR / teardown+retry runs - Make redirect guard strictly one-shot: consume (clear) on first use so repeated null events never re-trigger the snapshot path - Also enforce TTL as a belt-and-suspenders cutoff - Clear all guard state unconditionally in the normal auth-event path - Update clearRedirectAuthGuard and teardownAuthBootstrapForTests to reset redirectUserGuardSetAt - Add explanatory comments throughout guard logic
Copilot
AI
changed the title
[WIP] Refactor ensureAuthBootstrapped to eliminate redirect loops
fix(auth): eliminate redirect loops in ensureAuthBootstrapped
Jun 28, 2026
DHCross
approved these changes
Jun 28, 2026
Rebase PR #878 onto current main while preserving REDIRECT_PENDING_MAX_AGE_MS, isFreshGoogleRedirectPending, and REDIRECT_INCOMPLETE_MESSAGE behavior from main. Add one-shot redirectUserGuard consumption with TTL, unsubscribe previous onAuthStateChanged before attaching a new listener, and comprehensive tests. Co-authored-by: DHCross <DHCross@users.noreply.github.com>
|
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.



The
redirectUserGuardwas never consumed after firing, so every subsequentnullevent fromonAuthStateChangedwould re-push the redirect snapshot — causing bounce loops back to the sign-in screen. Additionally, the previousonAuthStateChangedlistener was never unsubscribed before attaching a new one, allowing accumulation across HMR reloads and test teardown/retry cycles.Changes
redirectUserGuard,redirectUserSnapshot,redirectUserGuardSetAt) is cleared atomically on first use, so futurenullevents propagate naturally instead of re-triggering the snapshot pathREDIRECT_GUARD_TTL_MS = 10_000as a belt-and-suspenders cutoff; the guard cannot fire after 10 s regardless of one-shot logicunsubscribeOngoing?.()is called before everyonAuthStateChangedcall, preventing listener accumulation on HMR / teardown+retry runssignedInUserwas truthy; now cleared unconditionally so stale/expired guard state can never lingerredirectUserGuardSetAtpropagated to resets —clearRedirectAuthGuardandteardownAuthBootstrapForTestsboth reset the new timestamp fieldThe persistence →
getRedirectResult→onAuthStateChangedordering is preserved.Original prompt