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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user