fix(middleware): remove redirect on stale token so login page can load#50
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Fixes an auth-flow edge case where a stale/invalid token cookie prevented users from reaching /login by removing middleware-based redirects for auth routes and shifting redirect behavior to the client after session validation.
Changes:
- Removed middleware redirect that forced any token-bearing request on auth routes to
/dashboard. - Added client-side redirect on the login page when
AuthProviderconfirms an authenticated session. - Updated login page navigation imports to support the redirect.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/web-next/src/middleware.ts | Stops redirecting auth routes based solely on token presence, allowing login/register pages to load even with stale cookies. |
| apps/web-next/src/app/(auth)/login/page.tsx | Redirects authenticated users away from /login after client-side session validation. |
Comments suppressed due to low confidence (2)
apps/web-next/src/middleware.ts:208
- The middleware change fixes a regression-prone redirect edge case (stale/invalid token on
/login). There isn’t an automated test covering this behavior today; please add a Playwright test that sets a bogusnaap_auth_tokencookie and verifies/loginrenders (and does not redirect to/dashboard).
const response = NextResponse.next();
response.headers.set('x-request-id', requestId);
response.headers.set('x-trace-id', traceId);
return response;
apps/web-next/src/middleware.ts:208
- After removing the auth-route redirect block,
authRoutesis no longer referenced anywhere in this middleware file, which will trigger the configured ESLint@typescript-eslint/no-unused-varswarning. Please removeauthRoutes(and update the associated comment) or re-introduce a concrete usage so the list isn’t dead code.
const response = NextResponse.next();
response.headers.set('x-request-id', requestId);
response.headers.set('x-trace-id', traceId);
return response;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📝 WalkthroughWalkthroughRelocates auth redirect logic from server-side middleware to the client-side login page: middleware no longer auto-redirects authenticated users away from auth routes; the login page now performs a client-side redirect to a safe path when auth state indicates the user is authenticated. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
The merge-base changed after approval.
|
|
- Modify middleware to prevent redirection for authenticated users accessing auth routes, allowing the login page to load even with a stale token. - Enhance LoginPage component to redirect authenticated users to the dashboard after successful login, improving user experience and handling valid tokens correctly.
0a7b9fd to
95a1a7d
Compare
Summary
Fixes a bug where users with a stale or invalid auth token were unable to reach the login page. Middleware redirected them to the dashboard, which would then fail auth and could leave the app stuck. This PR lets the login page load for auth routes regardless of token presence, and validates the token client-side so valid sessions still redirect to the dashboard.
Changes
/loginand/registerto/dashboard. Auth routes are now allowed through;AuthProviderhandles validation and redirects.useEffectthat redirects authenticated users to/dashboardwhenAuthProviderconfirms a valid session.useRouterfor the redirect logic.Type
Plugin(s) Affected
Checklist
npm run lint)npm run build)Breaking Changes
None
Screenshots / Recordings
Summary by CodeRabbit
Bug Fixes
Chores