UNPKG

bknd

Version:

Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.

70 lines (69 loc) 2.45 kB
import { type AppPlugin, type DB, type FieldSchema, type MaybePromise, type EntityConfig } from "../.."; export type EmailOTPPluginOptions = { /** * Customize code generation. If not provided, a random 6-digit code will be generated. */ generateCode?: (user: Pick<DB["users"], "email">) => string; /** * The base path for the API endpoints. * @default "/api/auth/otp" */ apiBasePath?: string; /** * The TTL for the OTP tokens in seconds. * @default 600 (10 minutes) */ ttl?: number; /** * The name of the OTP entity. * @default "users_otp" */ entity?: string; /** * The config for the OTP entity. */ entityConfig?: EntityConfig; /** * Customize email content. If not provided, a default email will be sent. */ generateEmail?: (otp: EmailOTPFieldSchema) => MaybePromise<{ subject: string; body: string | { text: string; html: string; }; }>; /** * Enable debug mode for error messages. * @default false */ showActualErrors?: boolean; /** * Allow direct mutations (create/update) of OTP codes outside of this plugin, * e.g. via API or admin UI. If false, mutations are only allowed via the plugin's flows. * @default false */ allowExternalMutations?: boolean; /** * Whether to send the email with the OTP code. * @default true */ sendEmail?: boolean; }; declare const otpFields: { action: import("../../data/fields").EnumField<false, string> & { required: () => import("../../data/fields").EnumField<true, string>; }; code: import("../../data/fields").TextField<true>; email: import("../../data/fields").TextField<true>; created_at: import("../../data/fields").DateField<false> & { required: () => import("../../data/fields").DateField<true>; }; expires_at: import("../../data/fields").DateField<true>; used_at: import("../../data/fields").DateField<false> & { required: () => import("../../data/fields").DateField<true>; }; }; export type EmailOTPFieldSchema = FieldSchema<typeof otpFields>; export declare function emailOTP({ generateCode: _generateCode, apiBasePath, ttl, entity: entityName, entityConfig, generateEmail: _generateEmail, showActualErrors, allowExternalMutations, sendEmail, }?: EmailOTPPluginOptions): AppPlugin; export {};