fix(auth): use router.replace for protected-page login redirects (#46) - #199
Merged
presidojay1 merged 2 commits intoSep 26, 2026
Merged
presidojay1 merged 2 commits into
presidojay1 merged 2 commits into
Conversation
Protected-page counterpart to useRedirectIfAuthenticated (StellarTickets#50): once auth has loaded and there is no user, router.replace('/login') so the protected URL isn't left in history. Refs StellarTickets#46
Replace the per-page router.push('/login') effects in dashboard,
dashboard/organizations/[id], dashboard/events/[id], my-tickets, verify
and marketplace with useRequireAuth(), which uses router.replace, so the
protected URL is not left in history. Drops now-unused useRouter /
useEffect imports.
Closes StellarTickets#46
|
@richardtoms100 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
Every protected page redirected signed-out users with
router.push('/login')in an effect.pushleaves the protected URL in history, so pressing Back from/loginreturned to the protected page, which immediately pushed/loginagain. The user could never go back past it.Fix
Commit 1:
src/lib/use-require-auth.ts(new) + testsThis is the protected-page counterpart to
useRedirectIfAuthenticated(#50 / #198), which already usesrouter.replacefor the guest-only pages. The two redirect directions now share the same pattern.Commit 2: adopt it on all six protected pages
dashboardrouter.push('/login')effectuseRequireAuth()dashboard/organizations/[id]router.push("/login")effectuseRequireAuth()dashboard/events/[id]router.push('/login')effectuseRequireAuth()my-ticketsrouter.push('/login')effectuseRequireAuth()verifyrouter.push('/login')effectuseRequireAuth()marketplacerouter.push('/login')effectuseRequireAuth()The
router/useRouter/useEffectimports that each page no longer uses were removed (none of these pages usedrouterfor anything else).grepconfirms nopush('/login')is left insrc/.Tests:
src/lib/use-require-auth.test.ts(5)router.replace('/login'), androuter.pushis never called. This is the regression guard for Auth redirects userouter.push, trapping the browser Back button #46.loading.The repo has no
@testing-library/react, so the tests mount a probe component withreact-dom/client+actunder the existing jsdom Vitest config, withnext/navigationandauth-contextmocked.Verification
npx vitest run: 15 files, 71/71 tests pass, including the 5 new ones.eslintis clean on the changed pages and the new files.tsc --noEmitshows no errors from this change.main(not touched here)src/app/my-tickets/page.tsxalready fails to parse onmain, before this PR (tsc:TS17008 JSX element 'div' has no corresponding closing tagaround line 274/329). It looks like a merge left theView on-chain<a>block without its wrapping conditional's closing. This PR's change to that file is only the 7-line redirect swap near the top. The JSX breakage should be fixed separately, because it will failnext buildregardless of this PR.Closes #46
Closes #47
Closes #48
Closes #49