fix: restore login by dropping broken Supabase Kong rewrite

Middleware getUser() could not validate the session cookie via the
internal Docker hostname, so auth succeeded in the browser but kept
redirecting back to /login stuck on "Verificando".

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-10-05 16:14:00 +02:00
parent a6509bb89c
commit bb5f721b38
3 changed files with 15 additions and 38 deletions

View File

@@ -1,11 +1,13 @@
import { createServerClient } from '@supabase/ssr';
import { NextRequest, NextResponse } from 'next/server';
function withSecurityHeaders(res: NextResponse) {
function withSecurityHeaders(res: NextResponse, path?: string) {
res.headers.set('X-Frame-Options', 'DENY');
res.headers.set('X-Content-Type-Options', 'nosniff');
res.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
res.headers.set('X-Robots-Tag', 'noindex, nofollow');
if (!path?.startsWith('/legal')) {
res.headers.set('X-Robots-Tag', 'noindex, nofollow');
}
res.headers.set(
'Permissions-Policy',
'camera=(), microphone=(), geolocation=()'
@@ -24,26 +26,12 @@ export async function middleware(req: NextRequest) {
request: { headers: req.headers },
});
// Public Supabase URL only — Docker-internal Kong rewrite made getUser() fail
// after login (cookie set, middleware treats user as logged out → stuck verifying).
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
global: {
fetch: (url: string | URL | Request, options?: RequestInit) => {
const u = new URL(url.toString());
if (process.env.NODE_ENV === 'production' && u.hostname === 'supabase.4ventures.es') {
u.protocol = 'http:';
u.hostname = 'ventures-web-supabase-gm0nnn-supabase-kong';
u.port = '8000';
if (!options) options = {};
if (!options.headers) options.headers = new Headers();
const headers = new Headers(options.headers);
headers.set('Host', 'supabase.4ventures.es');
options.headers = headers;
}
return fetch(u.toString(), options);
}
},
cookies: {
getAll() {
return req.cookies.getAll();