From 3351d740583302bb1c84c6ea99e6d880a173a67d Mon Sep 17 00:00:00 2001 From: Paperclip Date: Tue, 14 Apr 2026 16:03:37 +0000 Subject: [PATCH] fix: add startup validation to auth service config - Add DATABASE_URL validation after BETTER_AUTH_SECRET check - Warn clearly when DATABASE_URL is not set (uses localhost default) - Move pool declaration after validation blocks Co-Authored-By: Paperclip --- auth/src/auth.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/auth/src/auth.ts b/auth/src/auth.ts index b1e0e1b..202802c 100644 --- a/auth/src/auth.ts +++ b/auth/src/auth.ts @@ -4,17 +4,23 @@ import pg from "pg"; const { Pool } = pg; -const pool = new Pool({ - connectionString: - process.env.DATABASE_URL ?? - "postgresql://cartsnitch:cartsnitch@localhost:5432/cartsnitch", -}); - const secret = process.env.BETTER_AUTH_SECRET; if (!secret) { throw new Error("BETTER_AUTH_SECRET environment variable is required"); } +const databaseUrl = process.env.DATABASE_URL; +if (!databaseUrl) { + console.warn( + "WARNING: DATABASE_URL is not set — using default localhost connection. " + + "Set DATABASE_URL for production deployments." + ); +} + +const pool = new Pool({ + connectionString: databaseUrl ?? "postgresql://cartsnitch:cartsnitch@localhost:5432/cartsnitch", +}); + export const auth = betterAuth({ database: pool, basePath: "/auth",