fix(auth): redirect signed-in users away from /login and /register (#50) - #198
Merged
presidojay1 merged 2 commits intoSep 26, 2026
Conversation
Add useRedirectIfAuthenticated: once auth has finished loading, a signed-in user is sent to /dashboard via router.replace (so the form isn't left in history), and the page renders nothing meanwhile so the form never flashes. Use it on the login page.
…ts#50) Reuse useRedirectIfAuthenticated on the register page so an authenticated user visiting /register is replaced to /dashboard instead of seeing the sign-up form.
presidoclintonbased-alt
requested a review
from presidojay1
as a code owner
September 26, 2026 17:24
|
@presidoclintonbased-alt 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! 🚀 |
❌ Deploy Preview for stellartickets failed.
|
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
Visiting
/loginor/registerwhile signed in showed the auth form again.Changes
src/lib/use-redirect-if-authenticated.ts(new)useRedirectIfAuthenticated(to = '/dashboard'):useAuth().loadingisfalseand there is auser, it callsrouter.replace(to). Usingreplace, notpush, keeps the auth page out of history, so Back doesn't bounce the user to it.truewhile the page should render nothing, meaning auth is still loading or a redirect is in flight. A signed-in user therefore never sees the form flash.DEFAULT_AUTHENTICATED_PATH = '/dashboard'matches where login and register already send users after a successful submit.Login and register pages
Both call the hook and return
nullwhile it reportsredirecting. Everything else on both pages is unchanged.Commits
fix(auth): redirect signed-in users away from /login (#50): the hook plus the login pagefix(auth): redirect signed-in users away from /register (#50)Testing
Not run locally. Manual check:
/login: it immediately replaces to/dashboard, and Back doesn't return to/login./register.Closes Signed-in users can still open /login and /register #50
Closes Auth state is not synchronised across browser tabs #51
Closes Memoise the
AuthContextvalue so consumers don't re-render on every provider render #52Closes
apiFetchsendsContent-Type: application/jsonon body-less requests, forcing needless CORS preflights #53