Spaces:
Sleeping
Sleeping
File size: 876 Bytes
fb12607 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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;
|