Allow COOKIE_SECURE=false to disable Secure flag behind HTTP proxy

NODE_ENV=production sets Secure:true but the container may sit behind
an HTTP-only reverse proxy, causing browsers to reject the cookie.
COOKIE_SECURE=false in .env overrides the flag without changing NODE_ENV.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chris 2026-04-13 18:51:45 -04:00
parent c8fc15be86
commit e34dfc397c

View File

@ -51,9 +51,12 @@ export async function POST(request: Request) {
const token = deriveSessionToken(process.env.ADMIN_PASSWORD) const token = deriveSessionToken(process.env.ADMIN_PASSWORD)
const response = NextResponse.json({ ok: true }) const response = NextResponse.json({ ok: true })
// Secure flag: on by default in production, but can be disabled via
// COOKIE_SECURE=false in .env when running behind an HTTP-only proxy.
const secureCookie = process.env.COOKIE_SECURE !== 'false' && process.env.NODE_ENV === 'production'
response.cookies.set('admin_token', token, { response.cookies.set('admin_token', token, {
httpOnly: true, httpOnly: true,
secure: process.env.NODE_ENV === 'production', secure: secureCookie,
sameSite: 'strict', sameSite: 'strict',
maxAge: 60 * 60 * 24 * 7, // 7 days maxAge: 60 * 60 * 24 * 7, // 7 days
path: '/', path: '/',