import type { GeneratedTypes, TypedUser } from 'payload'; export type ResolveAuthCollectionSlug = 'auth' extends keyof T ? keyof T['auth'] : string; export type AuthCollectionSlug = ResolveAuthCollectionSlug; export type OTPPluginCollectionOptions = { /** * If you would like to handle sending the OTP yourself, via SMS or similar, * disable the email that is sent by passing `true`. */ disableEmail?: boolean; /** * Define how many seconds for the one-time password to be valid. Defaults to 5 minutes. */ exp?: number; /** * Customize the HTML that is sent in the OTP email sent to the user. */ generateOTPEmailHTML?: GenerateOTPEmailHTML; /** * Customize the subject that is sent in the OTP email sent to the user. */ generateOTPEmailSubject?: GenerateOTPEmailSubject; /** * Hook into plugin actions. */ hooks?: { /** * These hooks will run after the OTP is saved on the user. */ afterSetOTP?: AfterSetOTPHook[]; }; }; export type OTPPluginOptions = { /** * Set `admin: false` to disable any modifications to the Payload admin UI. * This is useful if you are using this plugin in your own frontends, but not * within the admin UI itself. * * Alternatively, pass an object with `defaultToOTP: true` to make OTP the default login method. */ admin?: { /** * When enabled, the default login page (/admin/login) will use OTP authentication. * The standard email/password login will still be accessible at /admin/login/default. * * @default false */ defaultToOTP?: boolean; } | false; /** * Define options for each auth-enabled collection you want to enable OTP for. */ collections: Partial<{ [K in AuthCollectionSlug]: OTPPluginCollectionOptions | true; }>; }; export type AfterSetOTPHook = (args: { /** * The collection slug that the user belongs to. */ collection: TSlug; /** * The one-time password that was saved on the user. */ otp: string; /** * The user that has requested a one-time password. */ user: TypedUser; }) => Promise; export type GenerateOTPEmailArgs = { /** * The collection slug that the user belongs to. */ collection: TSlug; /** * The one-time password that was saved on the user. */ otp: string; /** * The user that has requested a one-time password. */ user: TypedUser; }; export type GenerateOTPEmailHTML = (args: GenerateOTPEmailArgs) => Promise | string; export type GenerateOTPEmailSubject = (args: GenerateOTPEmailArgs) => Promise | string; export type FindUserType = { type: 'email'; value: string; } | { type: 'id'; value: number | string; } | { type: 'username'; value: string; };