Skip to content

Commit 8c27eac

Browse files
Fix auth cookie secure flag for HTTP in production
- Changed cookie secure flag to check actual request protocol instead of NODE_ENV - Cookies now work correctly in production when accessing over HTTP - Fixes authentication redirect issue in production mode
1 parent 86056c9 commit 8c27eac

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/app/api/auth/login/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ export async function POST(request: NextRequest) {
4747
username
4848
});
4949

50+
// Determine if request is over HTTPS
51+
const isSecure = request.url.startsWith('https://');
52+
5053
// Set httpOnly cookie with configured duration
5154
response.cookies.set('auth-token', token, {
5255
httpOnly: true,
53-
secure: process.env.NODE_ENV === 'production',
56+
secure: isSecure, // Only secure if actually over HTTPS
5457
sameSite: 'strict',
5558
maxAge: sessionDurationDays * 24 * 60 * 60, // Use configured duration
5659
path: '/',

0 commit comments

Comments
 (0)