From 716e2e7d2841c10c9b922ff315bf8452abeeafd5 Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Thu, 21 Mar 2024 17:20:50 -0700 Subject: [PATCH] Trying to fix auth cookie. --- src/lib/server/auth.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/server/auth.ts b/src/lib/server/auth.ts index 8cf6efa..7c90149 100644 --- a/src/lib/server/auth.ts +++ b/src/lib/server/auth.ts @@ -6,6 +6,15 @@ import { sessions, users } from '../../schema'; const adapter = new DrizzlePostgreSQLAdapter(db, sessions, users); +let domain; +if (process.env.NODE_ENV === 'production' || process.env.VERCEL_ENV === 'production') { + domain = 'boredgame.vercel.app'; +} else if (process.env.VERCEL_ENV === 'preview' || process.env.VERCEL_ENV === 'development') { + domain = process.env.VERCEL_BRANCH_URL; +} else { + domain = 'localhost'; +} + export const lucia = new Lucia(adapter, { getSessionAttributes: (attributes) => { return { @@ -30,10 +39,7 @@ export const lucia = new Lucia(adapter, { // set to `true` when using HTTPS secure: process.env.NODE_ENV === 'production', sameSite: 'strict', - domain: - process.env.NODE_ENV === 'production' - ? process.env.VERCEL_URL ?? 'boredgame.vercel.app' - : 'localhost' + domain } } });