Email OTP - new endpoint /email-otp/reset-password-verify-otp #1309

Closed
opened 2026-03-13 08:32:11 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @felipedeboni on GitHub (Jun 5, 2025).

Is this suited for github?

  • Yes, this is suited for github

No response

Describe the solution you'd like

I would like to be able to do a multi-step form for the reset password flow, and to be able to do it with a good UX we need to be able to verify the OTP before showing the reset password form (password and confirm password fields)

It's basically the same as resetPasswordEmailOTP function without the final part.

Our reset password flow:

Step 1: we ask user's email.

emailOtp.sendVerificationOtp({
  email: formData.email,
  type: "forget-password"
});

Step 2: we ask the OTP and verify it.

await emailOtp.verifyOtp({
  email,
  otp: formData.otp
});

Step 3: finally we reset the password.

await emailOtp.resetPassword({
  email,
  otp,
  password: formData.password,
});

Describe alternatives you've considered

The alternative is to patch better-auth package :)

Additional context

New method is a copy of resetPasswordEmailOTP, removed lines from 743 to 768 - duplicating code makes easier than extracting logic and sharing it when patching in future updates.

File: packages/better-auth/src/plugins/email-otp/index.ts

await ctx.context.internalAdapter.deleteVerificationValue(
  verificationValue.id,
);
const passwordHash = await ctx.context.password.hash(
  ctx.body.password,
);
const account = user.accounts.find(
  (account) => account.providerId === "credential",
);
if (!account) {
  await ctx.context.internalAdapter.createAccount(
    {
    	userId: user.user.id,
    	providerId: "credential",
    	accountId: user.user.id,
    	password: passwordHash,
    },
    ctx,
  );
} else {
  await ctx.context.internalAdapter.updatePassword(
    user.user.id,
    passwordHash,
    ctx,
  );
}
Originally created by @felipedeboni on GitHub (Jun 5, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. _No response_ ### Describe the solution you'd like I would like to be able to do a multi-step form for the reset password flow, and to be able to do it with a good UX we need to be able to verify the OTP before showing the reset password form (password and confirm password fields) It's basically the same as `resetPasswordEmailOTP` function without the final part. Our reset password flow: Step 1: we ask user's email. ```tsx emailOtp.sendVerificationOtp({ email: formData.email, type: "forget-password" }); ``` Step 2: we ask the OTP and verify it. ```tsx await emailOtp.verifyOtp({ email, otp: formData.otp }); ``` Step 3: finally we reset the password. ```tsx await emailOtp.resetPassword({ email, otp, password: formData.password, }); ``` ### Describe alternatives you've considered The alternative is to patch better-auth package :) ### Additional context New method is a copy of `resetPasswordEmailOTP`, removed lines from `743` to `768` - duplicating code makes easier than extracting logic and sharing it when patching in future updates. File: `packages/better-auth/src/plugins/email-otp/index.ts` ```tsx await ctx.context.internalAdapter.deleteVerificationValue( verificationValue.id, ); const passwordHash = await ctx.context.password.hash( ctx.body.password, ); const account = user.accounts.find( (account) => account.providerId === "credential", ); if (!account) { await ctx.context.internalAdapter.createAccount( { userId: user.user.id, providerId: "credential", accountId: user.user.id, password: passwordHash, }, ctx, ); } else { await ctx.context.internalAdapter.updatePassword( user.user.id, passwordHash, ctx, ); } ```
Author
Owner

@dosubot[bot] commented on GitHub (Sep 4, 2025):

Hi, @felipedeboni. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested a new endpoint, /email-otp/reset-password-verify-otp, to separate OTP verification from the password reset form.
  • The goal is to improve user experience by enabling a multi-step password reset flow.
  • Your proposal involves duplicating some code to avoid modifying the existing resetPasswordEmailOTP function and ease future patching.
  • There has been no further activity or discussion on this issue since your initial request.

Next Steps:

  • Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Sep 4, 2025): Hi, @felipedeboni. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested a new endpoint, `/email-otp/reset-password-verify-otp`, to separate OTP verification from the password reset form. - The goal is to improve user experience by enabling a multi-step password reset flow. - Your proposal involves duplicating some code to avoid modifying the existing `resetPasswordEmailOTP` function and ease future patching. - There has been no further activity or discussion on this issue since your initial request. **Next Steps:** - Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1309