[GH-ISSUE #868] email OTP Verification not signing user in on verification success. #8473

Closed
opened 2026-04-13 03:33:09 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @leonlonsdale on GitHub (Dec 12, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/868

Describe the bug

  1. The OTP plugin does not automatically issue a verification email on signup when the sendVerificationOnSignup option is set to true.

  2. When successfully verifying the OTP, the user is not automatically signed in.

To Reproduce
Steps to reproduce the behavior:

  1. No automatic OTP email sending
  • Setup the OTP plugin.
  • Create an account with email & password
    // no email is sent
  1. No automatic login.
  • add the sendVerificationOtp func to the 1st setup, and repeat steps in 1)
  • enter received Otp code into emailOtp.verifyEmail
    // user is not logged in

Expected behavior
A clear and concise description of what you expected to happen.

I would expect that setting sendVerificationOnSignup to true would automatically send an OTP to the users email when they submit a new username and password for a new account.

I would expect that the user is automatically logged in when the verification is successful.

Originally created by @leonlonsdale on GitHub (Dec 12, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/868 **Describe the bug** 1) The OTP plugin does not automatically issue a verification email on signup when the sendVerificationOnSignup option is set to true. 2) When successfully verifying the OTP, the user is not automatically signed in. **To Reproduce** Steps to reproduce the behavior: 1) No automatic OTP email sending - Setup the OTP plugin. - Create an account with email & password // no email is sent 2) No automatic login. - add the sendVerificationOtp func to the 1st setup, and repeat steps in 1) - enter received Otp code into emailOtp.verifyEmail // user is not logged in **Expected behavior** A clear and concise description of what you expected to happen. I would expect that setting sendVerificationOnSignup to true would automatically send an OTP to the users email when they submit a new username and password for a new account. I would expect that the user is automatically logged in when the verification is successful.
GiteaMirror added the lockedbug labels 2026-04-13 03:33:09 -05:00
Author
Owner

@svaraborut commented on GitHub (Dec 15, 2024):

I think neither conventional token verification performs automated sign-in after verification. This may be a bug we are carrying on since pre v1

<!-- gh-comment-id:2543513268 --> @svaraborut commented on GitHub (Dec 15, 2024): I think neither conventional token verification performs automated sign-in after verification. This may be a bug we are carrying on since pre v1
Author
Owner

@Bekacru commented on GitHub (Dec 16, 2024):

  1. I think it's probably because emailVerified is null. The plugin strictly checks for a false value. We should patch that.
  2. sendVerificationOTP doesn't sign in the user automatically. You should use authClient.signIn.emailOTP instead, which will sign in the user upon verification.
<!-- gh-comment-id:2545046346 --> @Bekacru commented on GitHub (Dec 16, 2024): 1. I think it's probably because `emailVerified` is null. The plugin strictly checks for a `false` value. We should patch that. 2. `sendVerificationOTP` doesn't sign in the user automatically. You should use `authClient.signIn.emailOTP` instead, which will sign in the user upon verification.
Author
Owner

@leonlonsdale commented on GitHub (Dec 16, 2024):

  1. I think it's probably because emailVerified is null. The plugin strictly checks for a false value. We should patch that.
  2. sendVerificationOTP doesn't sign in the user automatically. You should use authClient.signIn.emailOTP instead, which will sign in the user upon verification.

The sendVerificationOTP is fine, but if you send a verification email using sendVerificationOTP with type = email-verification and then attempt to use authClient.signIn.emailOTP, you get invalid otp error. Using authClient.emailOtp.verifyEmaill works with the otp but the user is not signed in when they verify.

I think neither conventional token verification performs automated sign-in after verification. This may be a bug we are carrying on since pre v1

automated-sign in after verification works with the standard email verification method using the following options:

emailVerification: {
  sendOnSignUp: true,
  autoSignInAfterVerification: true,
  //...
}

It would be useful if emailOtp.verifyEmail did the same. From a dev pov it's no issue, we can redirect the user to login, but from a UX that flow isn't ideal.

<!-- gh-comment-id:2545555431 --> @leonlonsdale commented on GitHub (Dec 16, 2024): > 1. I think it's probably because `emailVerified` is null. The plugin strictly checks for a `false` value. We should patch that. > 2. `sendVerificationOTP` doesn't sign in the user automatically. You should use `authClient.signIn.emailOTP` instead, which will sign in the user upon verification. The sendVerificationOTP is fine, but if you send a verification email using sendVerificationOTP with type = email-verification and then attempt to use authClient.signIn.emailOTP, you get invalid otp error. Using authClient.emailOtp.verifyEmaill works with the otp but the user is not signed in when they verify. > I think neither conventional token verification performs automated sign-in after verification. This may be a bug we are carrying on since pre v1 automated-sign in after verification works with the standard email verification method using the following options: ```ts emailVerification: { sendOnSignUp: true, autoSignInAfterVerification: true, //... } ``` It would be useful if emailOtp.verifyEmail did the same. From a dev pov it's no issue, we can redirect the user to login, but from a UX that flow isn't ideal.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8473