From 386e6f3cc72750022f1fb2ac5a765b1954a25984 Mon Sep 17 00:00:00 2001 From: Jez Date: Sat, 8 Nov 2025 14:51:19 +1100 Subject: [PATCH] fix: auto-detect port in auth client baseURL - Replace hardcoded localhost:3000 with window.location.origin - Enables auth to work on any port (3000, 3001, etc.) - Fixes issue when port 3000 is already in use - Maintains SSR compatibility with fallback env var --- src/modules/auth/utils/auth-client.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/modules/auth/utils/auth-client.ts b/src/modules/auth/utils/auth-client.ts index c06fe9f..7923257 100644 --- a/src/modules/auth/utils/auth-client.ts +++ b/src/modules/auth/utils/auth-client.ts @@ -4,9 +4,7 @@ import { createAuthClient } from "better-auth/react"; // The baseURL will be automatically determined from the current origin export const authClient = createAuthClient({ baseURL: - process.env.NODE_ENV === "development" - ? "http://localhost:3000" - : typeof window !== "undefined" - ? window.location.origin - : "", + typeof window !== "undefined" + ? window.location.origin // Auto-detect from browser URL (works for any port) + : process.env.NEXT_PUBLIC_AUTH_URL || "http://localhost:3000", // Fallback for SSR });