mirror of
https://github.com/documenso/documenso.git
synced 2025-11-09 20:12:31 +10:00
Adds support for 2FA when completing a document, also adds support for using email for 2FA when no authenticator has been associated with the account.
24 lines
610 B
TypeScript
24 lines
610 B
TypeScript
import { generateHOTP } from 'oslo/otp';
|
|
|
|
import { generateTwoFactorCredentialsFromEmail } from './generate-2fa-credentials-from-email';
|
|
|
|
export type GenerateTwoFactorTokenFromEmailOptions = {
|
|
documentId: number;
|
|
email: string;
|
|
period?: number;
|
|
};
|
|
|
|
export const generateTwoFactorTokenFromEmail = async ({
|
|
email,
|
|
documentId,
|
|
period = 30_000,
|
|
}: GenerateTwoFactorTokenFromEmailOptions) => {
|
|
const { secret } = generateTwoFactorCredentialsFromEmail({ email, documentId });
|
|
|
|
const counter = Math.floor(Date.now() / period);
|
|
|
|
const token = await generateHOTP(secret, counter);
|
|
|
|
return token;
|
|
};
|