UNPKG

kitcn

Version:

kitcn - React Query integration and CLI tools for Convex

51 lines (50 loc) 1.93 kB
import { U as LazyCaller, V as ConvexContext } from "../../procedure-name-BCRBr6Po.js"; import { t as GetTokenOptions } from "../../token-B9Bjcqug.js"; //#region src/auth-nextjs/index.d.ts /** Auth options for server-side calls. */ type AuthOptions = { /** Better Auth auth route base path. Defaults to `/api/auth`. */basePath?: string; /** Enable/disable JWT caching. Default: true */ jwtCache?: boolean; /** Custom function to detect UNAUTHORIZED errors. Default checks code property. */ isUnauthorized?: (error: unknown) => boolean; /** Expiration tolerance in seconds. */ expirationToleranceSeconds?: number; }; type ConvexBetterAuthOptions<TApi> = Omit<GetTokenOptions, 'jwtCache'> & { api: TApi; convexSiteUrl: string; convexUrl?: string; /** Auth options. JWT caching is enabled by default (set `auth.jwtCache: false` to disable). */ auth?: AuthOptions; }; /** * Create Convex caller factory with Better Auth integration for Next.js. * * @example * ```ts * // server.ts * export const { createContext, createCaller, handler } = convexBetterAuth({ * api, * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL, * }); // JWT caching enabled by default * * // rsc.tsx * const createRSCContext = cache(async () => { * const heads = await headers(); * return createContext({ headers: heads }); * }); * export const caller = createCaller(createRSCContext); * * // app/page.tsx - single call! * const posts = await caller.posts.list(); * ``` */ declare function convexBetterAuth<TApi extends Record<string, unknown>>(opts: ConvexBetterAuthOptions<TApi>): { createCaller: (ctxFn: () => Promise<ConvexContext<TApi>>) => LazyCaller<TApi>; createContext: (reqOpts: { headers: Headers; }) => Promise<ConvexContext<TApi>>; handler: { GET: (request: Request) => Promise<Response>; POST: (request: Request) => Promise<Response>; }; }; //#endregion export { convexBetterAuth };