// Better-auth client (use from React components)
import { createAuthClient } from "better-auth/react";

// Resolve baseURL at runtime in the browser to avoid `NEXT_PUBLIC_SITE_URL`
// being baked in at build-time (which falls back to localhost:3000 if the
// build environment doesn't have it set, breaking auth in production).
const baseURL =
  typeof window !== "undefined"
    ? window.location.origin
    : (process.env.NEXT_PUBLIC_SITE_URL ?? "http://localhost:3000");

export const authClient = createAuthClient({ baseURL });

export const { signIn, signUp, signOut, useSession, getSession } = authClient;
