Skip to content

fix(auth): redirect signed-in users away from /login and /register (#50) - #198

Merged
presidojay1 merged 2 commits into
StellarTickets:mainfrom
presidoclintonbased-alt:fix/50-redirect-authed-auth-pages
Sep 26, 2026
Merged

presidojay1 merged 2 commits into
StellarTickets:mainfrom
presidoclintonbased-alt:fix/50-redirect-authed-auth-pages

Conversation

@presidoclintonbased-alt

@presidoclintonbased-alt presidoclintonbased-alt commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Visiting /login or /register while signed in showed the auth form again.

Changes

src/lib/use-redirect-if-authenticated.ts (new)

useRedirectIfAuthenticated(to = '/dashboard'):

  • Redirect: once useAuth().loading is false and there is a user, it calls router.replace(to). Using replace, not push, keeps the auth page out of history, so Back doesn't bounce the user to it.
  • Return value: true while 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 null while it reports redirecting. Everything else on both pages is unchanged.

Commits

  • fix(auth): redirect signed-in users away from /login (#50): the hook plus the login page
  • fix(auth): redirect signed-in users away from /register (#50)

Testing

Not run locally. Manual check:

  1. Sign in.
  2. Visit /login: it immediately replaces to /dashboard, and Back doesn't return to /login.
  3. Do the same for /register.
  4. Signed out, both forms render as before.
    Closes Signed-in users can still open /login and /register #50
    Closes Auth state is not synchronised across browser tabs #51
    Closes Memoise the AuthContext value so consumers don't re-render on every provider render #52
    Closes apiFetch sends Content-Type: application/json on body-less requests, forcing needless CORS preflights #53

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.
@drips-wave

drips-wave Bot commented Sep 26, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@netlify

netlify Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for stellartickets failed.

Name Link
🔨 Latest commit fa3ee34
🔍 Latest deploy log https://app.netlify.com/projects/stellartickets/deploys/6ab7ffeb33f3d00009acdd6b

@presidojay1
presidojay1 merged commit 4c09c96 into StellarTickets:main Sep 26, 2026
0 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants