From b2c95037496f0f18a833d76bb6ba646a15534af3 Mon Sep 17 00:00:00 2001 From: Zaid Marzguioui Date: Wed, 1 Apr 2026 11:18:44 +0200 Subject: [PATCH] fix(proxy): graceful error handling when Supabase is unreachable Wrap getUser() calls in proxy.ts with try/catch so the proxy doesn't crash when the Supabase client can't connect. Without this, the proxy fails silently and Next.js returns 404 for all locale-dependent routes (/auth/sign-in, /join, etc.) because the locale rewrite never happens. --- Dockerfile | 2 +- apps/web/proxy.ts | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 476e302dd..090fe7028 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /app # --- Install + Build in one stage --- FROM base AS builder -ARG CACHE_BUST=7 +ARG CACHE_BUST=8 COPY . . RUN pnpm install --no-frozen-lockfile ENV NEXT_TELEMETRY_DISABLED=1 diff --git a/apps/web/proxy.ts b/apps/web/proxy.ts index 9feaa37b8..d8a78993a 100644 --- a/apps/web/proxy.ts +++ b/apps/web/proxy.ts @@ -80,7 +80,10 @@ async function adminMiddleware(request: NextRequest, response: NextResponse) { return; } - const { data, error } = await getUser(request, response); + const { data, error } = await getUser(request, response).catch(() => ({ + data: null as any, + error: new Error('Supabase unreachable'), + })); // If user is not logged in, redirect to sign in page. // This should never happen, but just in case. @@ -121,7 +124,14 @@ async function getPatterns() { { pattern: new URLPattern({ pathname: '/auth/*?' }), handler: async (req: NextRequest, res: NextResponse) => { - const { data } = await getUser(req, res); + let data; + + try { + ({ data } = await getUser(req, res)); + } catch { + // Supabase unreachable — treat as logged out, let the page render + return; + } // the user is logged out, so we don't need to do anything if (!data?.claims) { @@ -148,7 +158,16 @@ async function getPatterns() { { pattern: new URLPattern({ pathname: '/home/*?' }), handler: async (req: NextRequest, res: NextResponse) => { - const { data } = await getUser(req, res); + let data; + + try { + ({ data } = await getUser(req, res)); + } catch { + // Supabase unreachable — redirect to sign in + const signIn = pathsConfig.auth.signIn; + return NextResponse.redirect(new URL(signIn, req.nextUrl.origin).href); + } + const { origin, pathname: next } = req.nextUrl; // If user is not logged in, redirect to sign in page.