MicProtocol / apps /web /src /lib /auth-client.ts
Benaah's picture
Upload folder using huggingface_hub
fb12607 verified
Raw History Blame Contribute Delete
876 Bytes
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<Auth>(),
],
fetchOptions: {
// Always send cookies cross-origin (needed for subdomain routing)
credentials: "include",
},
});
export const { signIn, signUp, signOut, useSession } = authClient;