fix(two-factor): incorrect default OTP period & fix incorrect docs (#3231)

* docs(2fa): fix incorrect period

* fix: default period is 3 minutes

* Update packages/better-auth/src/plugins/two-factor/index.ts

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* chore: lint

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
Maxwell
2025-07-02 01:54:26 +10:00
committed by Bereket Engida
parent 4a5d798999
commit eea77a5020
2 changed files with 4 additions and 4 deletions

View File

@@ -393,7 +393,7 @@ these are options for TOTP.
default: 6, default: 6,
}, },
period: { period: {
description: "The period for otp in seconds.", description: "The period for totp in seconds.",
type: "number", type: "number",
default: 30, default: 30,
}, },
@@ -411,9 +411,9 @@ these are options for OTP.
type: "function", type: "function",
}, },
period: { period: {
description: "The period for otp in seconds.", description: "The period for otp in minutes.",
type: "number", type: "number",
default: 30, default: 3,
}, },
}} }}
/> />

View File

@@ -296,7 +296,7 @@ export const twoFactor = (options?: TwoFactorOptions) => {
*/ */
deleteSessionCookie(ctx, true); deleteSessionCookie(ctx, true);
await ctx.context.internalAdapter.deleteSession(data.session.token); await ctx.context.internalAdapter.deleteSession(data.session.token);
const maxAge = options?.otpOptions?.period || 60 * 5; // 5 minutes const maxAge = (options?.otpOptions?.period ?? 3) * 60; // 3 minutes
const twoFactorCookie = ctx.context.createAuthCookie( const twoFactorCookie = ctx.context.createAuthCookie(
TWO_FACTOR_COOKIE_NAME, TWO_FACTOR_COOKIE_NAME,
{ {