import type { AuthClient, BetterAuthClientOptions } from "better-auth/client"; import type { ReactAuthClient } from "better-auth/react"; import type { SolidAuthClient } from "better-auth/solid"; import type { SvelteAuthClient } from "better-auth/svelte"; import type { VueAuthClient } from "better-auth/vue"; import type { SafeResult } from "../../types/index.js"; /** Framework clients shipped by Better Auth — one `createAuthClient` per entry. */ export type AuthFramework = "vanilla" | "react" | "vue" | "svelte" | "solid"; export type { AuthClient, BetterAuthClientOptions }; /** Client type the requested framework's `createAuthClient` returns. */ export type AuthClientFor = F extends "vue" ? VueAuthClient : F extends "react" ? ReactAuthClient : F extends "svelte" ? SvelteAuthClient : F extends "solid" ? SolidAuthClient : AuthClient; export interface AuthClientOptions extends BetterAuthClientOptions { /** * Which Better Auth client entry to load. * * @defaultValue `"vanilla"` */ framework?: F; } export type AuthError = { message: string; details?: unknown; }; export type AuthResult = SafeResult; /** * Creates the Better Auth client for the requested framework, importing only * that entry — the other four never reach the bundle. * * @param options - `BetterAuthClientOptions` (`baseURL`, `plugins`, …) plus `framework` * @returns Safe result with the framework's typed client; never throws * * @example Vue / Nuxt — `lib/auth-client.ts` * ```ts * import { useAuthClient } from "katanakit-js/adapters/better-auth"; * * export const authClient = await useAuthClient({ framework: "vue" }); * export const { signIn, signUp, signOut, useSession } = authClient; * ``` * * @example React * ```ts * const authClient = await useAuthClient({ framework: "react", baseURL: "https://auth.example.com" }); * ``` * * @example Vanilla (Astro island-free pages, plain `