Files
CubeAdmin/lib/auth/client.ts
2026-03-08 15:49:34 +01:00

49 lines
1.5 KiB
TypeScript

"use client";
import { createAuthClient } from "better-auth/react";
import { organizationClient } from "better-auth/client/plugins";
import { magicLinkClient } from "better-auth/client/plugins";
import type { Auth } from "./index";
/**
* Better Auth client instance for use in React components and client-side
* code. Mirrors the plugins registered on the server-side `auth` instance.
*/
export const authClient = createAuthClient({
baseURL: process.env.NEXT_PUBLIC_BETTER_AUTH_URL ?? "http://localhost:3000",
plugins: [
// Enables organization.* methods (createOrganization, getActiveMember, etc.)
organizationClient(),
// Enables signIn.magicLink and magicLink.verify
magicLinkClient(),
],
});
// ---------------------------------------------------------------------------
// Convenience re-exports so consumers only need to import from this module
// ---------------------------------------------------------------------------
export const {
signIn,
signOut,
signUp,
useSession,
getSession,
} = authClient;
// ---------------------------------------------------------------------------
// Inferred client-side types
// ---------------------------------------------------------------------------
export type ClientSession = typeof authClient.$Infer.Session.session;
export type ClientUser = typeof authClient.$Infer.Session.user;
/**
* Infer server plugin types on the client side.
* Provides full type safety for plugin-specific methods without importing
* the server-only `auth` instance into a client bundle.
*/
export type { Auth };