Files
pn-new-crm/src/lib/auth/client.ts

16 lines
599 B
TypeScript
Raw Normal View History

'use client';
import { createAuthClient } from 'better-auth/react';
/**
* Use the current window origin as the auth API host so the same dev build
* works whether the page was loaded via http://localhost:3001 (Mac) or
* http://192.168.1.17:3001 (iPhone on LAN). Falls back to the build-time
* NEXT_PUBLIC_APP_URL during SSR / module-eval where `window` is undefined.
*/
export const authClient = createAuthClient({
baseURL: typeof window !== 'undefined' ? window.location.origin : process.env.NEXT_PUBLIC_APP_URL,
});
export const { useSession, signIn, signOut, getSession } = authClient;