Initial push
This commit is contained in:
48
lib/auth/client.ts
Normal file
48
lib/auth/client.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
"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 };
|
||||
Reference in New Issue
Block a user