mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-03 12:57:09 -05:00
fix(two-factor): verification deletion on otp should use the correct ID (#2425)
This commit is contained in:
@@ -255,9 +255,11 @@ export const otp2fa = (options?: OTPOptions) => {
|
||||
);
|
||||
const [otp, counter] = toCheckOtp?.value?.split("!") ?? [];
|
||||
if (!toCheckOtp || toCheckOtp.expiresAt < new Date()) {
|
||||
await ctx.context.internalAdapter.deleteVerificationValue(
|
||||
`2fa-otp-${key}`,
|
||||
);
|
||||
if (toCheckOtp) {
|
||||
await ctx.context.internalAdapter.deleteVerificationValue(
|
||||
toCheckOtp.id,
|
||||
);
|
||||
}
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
message: TWO_FACTOR_ERROR_CODES.OTP_HAS_EXPIRED,
|
||||
});
|
||||
@@ -265,7 +267,7 @@ export const otp2fa = (options?: OTPOptions) => {
|
||||
const allowedAttempts = options?.allowedAttempts || 5;
|
||||
if (parseInt(counter) >= allowedAttempts) {
|
||||
await ctx.context.internalAdapter.deleteVerificationValue(
|
||||
`2fa-otp-${key}`,
|
||||
toCheckOtp.id,
|
||||
);
|
||||
throw new APIError("BAD_REQUEST", {
|
||||
message: TWO_FACTOR_ERROR_CODES.TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE,
|
||||
|
||||
Reference in New Issue
Block a user