fix: full-page navigation after login so the session is applied (#365)#398
Merged
Conversation
Login signed in client-side then soft-navigated with router.push into /dashboard, a route the middleware gates on the Supabase session cookie. The soft navigation can reach the protected route before the server observes the freshly written cookies, so the middleware bounces it back to /login -- which looks like the page "just refreshing" instead of signing in. It surfaced over ngrok/HTTPS tunnels (added latency widens the window) while staying hidden on localhost. - login: navigate with window.location.href after signInWithPassword, mirroring the deliberate full reload the invite-accept flow already uses in join/[token]/page.tsx; drops the now-unused useRouter. - next.config: allow-list common dev tunnel origins (ngrok, cloudflared, localtunnel) so Next 16 stops 403-ing dev-only resources over the tunnel, extendable via ALLOWED_DEV_ORIGINS. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
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.
Summary
Over an ngrok tunnel, clicking Sign in just refreshed the login page instead of logging in — it worked fine on localhost.
Root cause
The login page signs in client-side, then does a soft navigation into a middleware-gated route:
/dashboardis protected bysrc/middleware.ts, which redirects to/loginunlesssupabase.auth.getUser()sees the session. A softrouter.pushcan reach the protected route before the server-side layer reliably observes the just-written auth cookies, so the middleware bounces/dashboard → /login— and the page appears to "just refresh."The repo already knows this pattern: the invite-accept flow in
src/app/join/[token]/page.tsxdeliberately uses a full reload ("not router.push, so AuthProvider re-fetches"). Login was the lone outlier still using the fragile soft navigation.Why ngrok and not localhost: environmental. HTTPS + proxy latency widen the timing window, and on Next.js 16 cross-origin dev resources (HMR, the dev overlay) are blocked by default unless the tunnel host is allow-listed.
Changes
src/app/(auth)/login/page.tsx— navigate withwindow.location.hrefaftersignInWithPassword, mirroring the join flow so the next top-level request carries the fresh cookies to the middleware (removes the now-unuseduseRouter).next.config.ts— addallowedDevOriginsfor common dev tunnels (ngrok / cloudflared / localtunnel), extendable viaALLOWED_DEV_ORIGINS, so Next 16 stops returning 403 for dev-only resources over the tunnel.Testing
tsc --noEmit✅eslint(changed files) ✅vitest run src/middleware.test.ts✅ (4/4)A full login-over-ngrok reproduction needs a live Supabase project + an active tunnel, which isn't available in the dev sandbox; the fix rests on the middleware logic, the passing checks, and consistency with the repo's existing full-reload convention.
Closes #365
🤖 Generated with Claude Code