import { createAuthClient } from "better-auth/react"; import { jwtClient, inferAdditionalFields } from "better-auth/client/plugins"; import type { Auth } from "@micprotocol/api"; const BETTER_AUTH_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:4000"; /** * Better Auth client — mirrors the server's jwt plugin so the client * can request a JWT session token for the Authorization header, and * inferAdditionalFields keeps session types in sync with the server's * auth config type export. */ export const authClient = createAuthClient({ baseURL: BETTER_AUTH_URL, plugins: [ jwtClient(), inferAdditionalFields(), ], fetchOptions: { // Always send cookies cross-origin (needed for subdomain routing) credentials: "include", }, }); export const { signIn, signUp, signOut, useSession } = authClient;