diff --git a/apps/server/src/modules/auth/next-auth.controller.ts b/apps/server/src/modules/auth/next-auth.controller.ts index 6119439e9a..1e562e7088 100644 --- a/apps/server/src/modules/auth/next-auth.controller.ts +++ b/apps/server/src/modules/auth/next-auth.controller.ts @@ -148,13 +148,15 @@ export class NextAuthController { } let nextAuthTokenCookie: (CookieOption & { value: string }) | undefined; + const cookiePrefix = this.config.node.prod ? '__Secure-' : ''; + const sessionCookieName = `${cookiePrefix}next-auth.session-token`; // next-auth credentials login only support JWT strategy // https://next-auth.js.org/configuration/providers/credentials // let's store the session token in the database if ( credentialsSignIn && (nextAuthTokenCookie = cookies?.find( - ({ name }) => name === 'next-auth.session-token' + ({ name }) => name === sessionCookieName )) ) { const cookieExpires = new Date();