Repository navigation
fix: /login renders without Supabase env (no 500 on deploy previews) - #58
Open
CosmonautJones wants to merge 1 commit into
Open
CosmonautJones wants to merge 1 commit into
CosmonautJones wants to merge 1 commit into
Conversation
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.
Root cause
src/middleware.ts:16callsupdateSession()for/tools,/admin,/login.updateSessioncallscreateServerClient(process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, …)atsrc/lib/supabase/middleware.ts:8-10(onmain). When those vars are unset,@supabase/ssrthrowsYour project's URL and Key are required to create a Supabase client!, so the middleware fails and every auth route returns 500. Netlify Deploy Previews don't have the vars, which is why previews 500 and prod is fine.Fix (minimal)
src/lib/supabase/middleware.ts: if!hasSupabaseConfig(), treat the request as anonymous./tools*and/admin*still redirect307 → /login?redirectTo=…. Everything else (including/login) isNextResponse.next(). No Supabase client is created.src/app/(auth)/login/page.tsx: passesauthAvailable={hasSupabaseConfig()}toLoginForm.src/components/auth/login-form.tsx: whenauthAvailableis false, shows the approved Portfolio Copy fallback in place of the GitHub button: Sign-in isn't available here / "This preview isn't connected to sign-in. Use the live site to sign in, or keep browsing the work." plus linksGo to the live site(https://www.travisjohnjones.com/login) andSee the work(/work).Verification (
next build && next start)/login/tools/login?redirectTo=%2Ftools/login?redirectTo=%2Ftools/admin/login?redirectTo=%2Fadmin/login?redirectTo=%2Fadmin/admin/tools/login?redirectTo=%2Fadmin%2Ftools/login?redirectTo=%2Fadmin%2Ftools/Checks:
eslint0 errors (1 existing warning in an untouched file,use-game-engine.ts).vitest105 files / 980 tests pass.next buildpasses with env both unset and set.tsc --noEmitshows the same 5 test-file errors asmain(being fixed on a separate branch) and no new ones.Tests added:
src/lib/supabase/__tests__/middleware-missing-env.test.ts: with env unset,/loginpasses through and/tools,/admin,/admin/toolsredirect to/loginwithredirectTo.createServerClientis never called.login-form.test.tsx: withauthAvailable={false}, the fallback copy and links render, there's no GitHub button, and no client is created.Note: this does not make sign-in work on previews
This PR only stops the 500s. To get real sign-in on previews:
NEXT_PUBLIC_SUPABASE_URLandNEXT_PUBLIC_SUPABASE_ANON_KEYfor Netlify's Deploy Previews context (Trav's Netlify account).https://deploy-preview-*--<site>.netlify.app/**) to the Supabase Auth redirect allowlist. Without it, GitHub sign-in can't complete the/auth/confirmredirect on previews.Do not merge until Trav.