Files
euchre_camp/src/lib/auth-client.ts
T
david 123df671f5 nextjs-rewrite (#5)
Reviewed-on: #5
Co-authored-by: David Gwilliam <dhgwilliam@gmail.com>
Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
2026-03-30 02:30:13 +00:00

21 lines
655 B
TypeScript

import { createAuthClient } from "better-auth/client";
// Get base URL from environment or use localhost as fallback
const getBaseURL = () => {
if (typeof window === 'undefined') {
return process.env.BETTER_AUTH_URL || "http://localhost:3000";
}
// For client-side, use the current origin but allow localhost variations
const origin = window.location.origin;
if (origin.includes('localhost') || origin.includes('127.0.0.1') || origin.includes('0.0.0.0')) {
return "http://localhost:3000"; // Normalize to localhost for Better Auth
}
return origin;
};
export const authClient = createAuthClient({
baseURL: getBaseURL(),
});