UNPKG

@accounts/two-factor

Version:

[![npm](https://img.shields.io/npm/v/@accounts/two-factor.svg)](https://www.npmjs.com/package/@accounts/two-factor) ![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)

33 lines (32 loc) 1.05 kB
import { type GeneratedSecret } from '@levminer/speakeasy'; import { type User, type DatabaseInterfaceUser } from '@accounts/types'; import { type AccountsTwoFactorOptions } from './types'; export declare class TwoFactor<CustomUser extends User = User> { private options; private db; private serviceName; private verifyTOTPCode; constructor(options?: AccountsTwoFactorOptions); /** * Set two factor store */ setUserStore(store: DatabaseInterfaceUser<CustomUser>): void; /** * Authenticate a user with a 2fa code */ authenticate(user: User, code: string): Promise<void>; /** * Generate a new two factor secret */ getNewAuthSecret(): GeneratedSecret; /** * Verify the code is correct * Add the code to the user profile * Throw if user already have 2fa enabled */ set(userId: string, secret: GeneratedSecret, code: string): Promise<void>; /** * Remove two factor for a user */ unset(userId: string, code: string): Promise<void>; }