[GH-ISSUE #3045] 2FA OTP custom period setting wrong unit and defaults mismatch #9447

Closed
opened 2026-04-13 04:54:49 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @sabvente on GitHub (Jun 16, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3045

To Reproduce

twoFactor({
  otpOptions: {
    period: 10
  }
})

Current vs. Expected behavior

Current behavior:

Unit mismatch

two-factor/otp/index.ts
treats period as minutes It converts it to milliseconds here (new Date expects milliseconds)

two-factor/index.ts
treats period as seconds (maxAge expects seconds)

Docs shows that "The period for otp in seconds."

Default value mismatch

two-factor/otp/index.ts
default value is 3 minutes

two-factor/index.ts
default value is 5 minutes

Docs shows that "The default period is 30 seconds for OTP.

#Expected behavior
Use the same units and same defaults everywhere.

What version of Better Auth are you using?

1.2.9

Which area(s) are affected? (Select all that apply)

Backend
Documentation

Originally created by @sabvente on GitHub (Jun 16, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3045 ### To Reproduce ```js twoFactor({ otpOptions: { period: 10 } }) ``` ### Current vs. Expected behavior # Current behavior: ## Unit mismatch [two-factor/otp/index.ts](https://github.com/better-auth/better-auth/blob/e4bed5c7866c2fa9c268d7fa3e561eedcadc84f2/packages/better-auth/src/plugins/two-factor/otp/index.ts#L67C3-L67C46) treats period as **minutes** It converts it to milliseconds here (new Date expects milliseconds) [two-factor/index.ts](https://github.com/better-auth/better-auth/blob/e4bed5c7866c2fa9c268d7fa3e561eedcadc84f2/packages/better-auth/src/plugins/two-factor/index.ts#L299C7-L299C73) treats period as **seconds** (maxAge expects seconds) Docs shows that "The period for otp in **seconds**." ## Default value mismatch [two-factor/otp/index.ts](https://github.com/better-auth/better-auth/blob/e4bed5c7866c2fa9c268d7fa3e561eedcadc84f2/packages/better-auth/src/plugins/two-factor/otp/index.ts#L67C3-L67C46) default value is **3 minutes** [two-factor/index.ts](https://github.com/better-auth/better-auth/blob/e4bed5c7866c2fa9c268d7fa3e561eedcadc84f2/packages/better-auth/src/plugins/two-factor/index.ts#L299C7-L299C73) default value is **5 minutes** Docs shows that "The default period is **30** seconds for OTP. #Expected behavior Use the same units and same defaults everywhere. ### What version of Better Auth are you using? 1.2.9 ### Which area(s) are affected? (Select all that apply) Backend Documentation
GiteaMirror added the lockedbug labels 2026-04-13 04:54:49 -05:00
Author
Owner

@ping-maxwell commented on GitHub (Jul 1, 2025):

The value in the code is using milliseconds is intentional, we take the provided value which is in minutes, then convert to ms - this is fine.
However the docs are incorrect, so I will update that. As well as the default otp period being 5 mins will be updated too.

<!-- gh-comment-id:3021549957 --> @ping-maxwell commented on GitHub (Jul 1, 2025): The value in the code is using milliseconds is intentional, we take the provided value which is in minutes, then convert to ms - this is fine. However the docs are incorrect, so I will update that. As well as the default otp period being 5 mins will be updated too.
Author
Owner

@sabvente commented on GitHub (Jul 1, 2025):

@ping-maxwell Thank you for fixing this! :)

<!-- gh-comment-id:3025121682 --> @sabvente commented on GitHub (Jul 1, 2025): @ping-maxwell Thank you for fixing this! :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9447