From e6ea744f0a8778ee22023ee6101b88da4e652e25 Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Thu, 21 Mar 2024 15:40:21 -0700 Subject: [PATCH] Fixing auth cookie value to be vercel url or backup. --- drizzle.config.ts | 4 ++-- src/lib/drizzle.ts | 4 ++-- src/lib/server/auth.ts | 13 ++++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/drizzle.config.ts b/drizzle.config.ts index b0bba9c..00c4ad5 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -11,10 +11,10 @@ export default defineConfig({ user: process.env.DATABASE_USER, password: process.env.DATABASE_PASSWORD, database: process.env.DATABASE || 'boredgame', - ssl: process.env.DATABASE_HOST === 'localhost' ? false : true, + ssl: process.env.DATABASE_HOST !== 'localhost' }, // Print all statements verbose: true, // Always as for confirmation strict: true -}); \ No newline at end of file +}); diff --git a/src/lib/drizzle.ts b/src/lib/drizzle.ts index d944d87..76ee71c 100644 --- a/src/lib/drizzle.ts +++ b/src/lib/drizzle.ts @@ -5,7 +5,7 @@ import { DATABASE_PASSWORD, DATABASE_HOST, DATABASE_DB, - DATABASE_PORT, + DATABASE_PORT } from '$env/static/private'; import * as schema from '../schema'; @@ -16,7 +16,7 @@ const pool = new pg.Pool({ host: DATABASE_HOST, port: Number(DATABASE_PORT).valueOf(), database: DATABASE_DB, - ssl: DATABASE_HOST === 'localhost' ? false : true, + ssl: DATABASE_HOST !== 'localhost' }); // user: DATABASE_USER, diff --git a/src/lib/server/auth.ts b/src/lib/server/auth.ts index 078733f..8cf6efa 100644 --- a/src/lib/server/auth.ts +++ b/src/lib/server/auth.ts @@ -1,6 +1,6 @@ // lib/server/lucia.ts import { Lucia, TimeSpan } from 'lucia'; -import { DrizzlePostgreSQLAdapter } from "@lucia-auth/adapter-drizzle"; +import { DrizzlePostgreSQLAdapter } from '@lucia-auth/adapter-drizzle'; import db from '$lib/drizzle'; import { sessions, users } from '../../schema'; @@ -22,7 +22,7 @@ export const lucia = new Lucia(adapter, { theme: attributes.theme }; }, - sessionExpiresIn: new TimeSpan(30, "d"), // 30 days + sessionExpiresIn: new TimeSpan(30, 'd'), // 30 days sessionCookie: { name: 'session', expires: false, // session cookies have very long lifespan (2 years) @@ -30,12 +30,15 @@ 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' ? 'boredgame.vercel.app' : 'localhost', + domain: + process.env.NODE_ENV === 'production' + ? process.env.VERCEL_URL ?? 'boredgame.vercel.app' + : 'localhost' } - }, + } }); -declare module "lucia" { +declare module 'lucia' { interface Register { Lucia: typeof lucia; DatabaseUserAttributes: DatabaseUserAttributes;