diff --git a/proxy.ts b/proxy.ts index afd76d4..19864fa 100644 --- a/proxy.ts +++ b/proxy.ts @@ -3,12 +3,19 @@ import { NextResponse, type NextRequest } from "next/server"; const PUBLIC_PATHS = ["/login"]; +function usesSecureAuthCookies() { + const authUrl = process.env.AUTH_URL ?? process.env.NEXTAUTH_URL; + + return authUrl?.startsWith("https://") ?? false; +} + export async function proxy(request: NextRequest) { const { pathname, search } = request.nextUrl; const isPublicPath = PUBLIC_PATHS.includes(pathname); const token = await getToken({ req: request, secret: process.env.AUTH_SECRET ?? process.env.NEXTAUTH_SECRET, + secureCookie: usesSecureAuthCookies(), }); if (!token && !isPublicPath) {