From 12ba95076a787cdf2d92c38a7afff2f77ad7ee63 Mon Sep 17 00:00:00 2001 From: sk1982 Date: Sun, 7 Apr 2024 02:50:08 -0400 Subject: [PATCH] add override cookie secure option --- src/auth.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/auth.ts b/src/auth.ts index 3671a08..8c1a069 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,4 +1,4 @@ -import NextAuth from 'next-auth'; +import NextAuth, { NextAuthConfig } from 'next-auth'; import CredentialsProvider from 'next-auth/providers/credentials'; import { db, GeneratedDB } from '@/db'; import { DBUserPayload } from '@/types/user'; @@ -31,10 +31,18 @@ const selectUserProps = (builder: SelectQueryBuilder = {}; + +if (['0', 'false', 'no'].includes(process.env.COOKIE_SECURE?.toLowerCase()!)) + config.useSecureCookies = false; +else if (['1', 'true', 'yes'].includes(process.env.COOKIE_SECURE?.toLowerCase()!)) + config.useSecureCookies = true; + const nextAuth = NextAuth({ pages: { signIn: `${basePath}/auth/login` }, + ...config, basePath: `${basePath}/api/auth/`, session: { strategy: 'jwt'