[GH-ISSUE #541] Resend OTP code doesn't work #8313

Closed
opened 2026-04-13 03:23:01 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ywyher on GitHub (Nov 15, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/541

when a user register i send an email containing the OTP required to verify his email using :

  await emailOtp.verifyEmail({
      email: email,
      otp: otp
  })

it does work successfully as expected, the issue is if the user doesn't receive the email
for this case i added a button that send the OTP again using

  await emailOtp.sendVerificationOtp({
      email: email,
      type: "email-verification",
  }

the function does add a record on the verification table without deleting the previous OTP code record, but when the user receive his new OTP code and try to verify the email with it, it throws invalid OTP, when i try the old OTP code it works
btw if i manually remove the previous OTP code record from the database, the new code works normally
is there a way to solve this ?

i was gonna try to delete the previous OTP code record from the database programmatically but there is no field in the verification table that i can use to indicate which OTP code belongs to which user

  • OS: arch linux
  • Browser: firefox
  • Version: better-auth "0.8.3"
Originally created by @ywyher on GitHub (Nov 15, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/541 when a user register i send an email containing the OTP required to verify his email using : ```tsx await emailOtp.verifyEmail({ email: email, otp: otp }) ``` it does work successfully as expected, the issue is if the user doesn't receive the email for this case i added a button that send the OTP again using ```tsx await emailOtp.sendVerificationOtp({ email: email, type: "email-verification", } ``` the function does add a record on the verification table **without deleting the previous OTP code record**, but when the user receive his new OTP code and try to verify the email with it, it throws invalid OTP, when i try the old OTP code it works btw if i manually remove the previous OTP code record from the database, the new code works normally is there a way to solve this ? i was gonna try to delete the previous OTP code record from the database programmatically but there is no field in the verification table that i can use to indicate which OTP code belongs to which user - OS: arch linux - Browser: firefox - Version: better-auth "0.8.3"
GiteaMirror added the locked label 2026-04-13 03:23:01 -05:00
Author
Owner

@Bekacru commented on GitHub (Nov 17, 2024):

this should be fixed. Feel free to re-open if this is still an issue.

<!-- gh-comment-id:2481257414 --> @Bekacru commented on GitHub (Nov 17, 2024): this should be fixed. Feel free to re-open if this is still an issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8313