Hotfix: spurious /set-username redirect & userInfo undefined error#343
Merged
Conversation
setUserInfo resolved on a hard-coded 1s timer while the actual SET_USERINFO commit was gated behind a slow await chain (server time, tiers, new_patrons query, getActivePatreonTier). When that chain outran the timer — on SSR cold loads (ctrl-click/new tab) or on high-latency connections — route guards saw an undefined userInfo and redirected to /set-username, which then threw reading userInfo.username. - setUserInfo now does an awaited .once() initial load, commits userInfo *before* the tier/voucher/patron enrichment, and resolves only after that commit. The live .on() listener is kept for updates. - Tier resolution moved to a guarded enrichTier action so a slow or failing patron lookup can never block or unset userInfo. - Route guards now redirect only when userInfo is loaded and has no username, distinguishing 'still loading' from 'no username'. - SetUsername preFetch guards against an undefined userInfo.
|
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.



Problem
Affected users are bounced to `/set-username` on login even though they already have a username (stored in the DB). The page then throws `TypeError: ... userInfo is undefined` (Firefox) / `Cannot read properties of undefined (reading 'username')` (Chrome). The same redirect was reproducible by anyone via ctrl-click / "open link in new tab" (a fresh SSR load).
Root cause
`userInfo` was committed (`SET_USERINFO`) only as the last line of an async `.on("value")` callback, after a chain of awaits — server time, tiers, a by-email `new_patrons` lookup, and `getActivePatreonTier`. Meanwhile `setUserInfo` resolved its returned promise on a hard-coded 1s timer, decoupled from that commit.
Two ways this broke:
Fix
Follow-up (data, not code)
If a user's login failure was caused by a corrupt `new_patrons` record, this stops it from breaking login but they'll silently get basic tier — inspect/repair that record separately.
Verification