1. Is it possible to auto turn on 2FA for user (2.) I need help with this authflow
---
🔐 Sign Up Flow
1. Enter Email
→ User provides their email address.
2. Send OTP
→ System sends an OTP to the email (
type: "email-verification"
).
3. Enter OTP
→ User enters the received OTP.
→ If valid: proceed
→ If invalid: reject and prompt retry
4. Set Password
→ Prompt the user to create a password.
5. Create Account
→ Register the user in the system.
6. Auto Sign-In
---
🔑 Sign In Flow
1. Enter Credentials
→ User inputs email and password.
2. Verify Credentials
→ If invalid: reject
→ If valid: proceed
3. Send OTP
→ System sends OTP to the user's email ( "sign-in"
).
4. Enter OTP
→ User inputs the OTP.
→ If valid: sign in
→ If invalid: reject and prompt retry
---
What I've tried
The issue with this is that authClient.emailOtp.verifyEmail also checks if the user exists already and obviously it doesn't so i get "User not found" from that block10 Replies
For the sign up code you provided, this is just over-engineering and can be done way easier. (Calling 3 times auth-client)
This will send an OTP-email anytime a user sign ups to their e-mail.
Enable
requireEmailVerification: true,
to prevent users from signin in before confirming their mail.
This is just for the backend part. For the client i think you will get along on how to track the e-mail state and verify the OTP.These docs have everything you need:
https://www.better-auth.com/docs/plugins/email-otp
Email OTP | Better Auth
Email OTP plugin for Better Auth.
Hi thinks i've done the signup but for the signin afterb authClient.signIn.email it creates the session immediately so the otp verification is it possible to turn on 2FA without the user's passwd
Look for the Two-factor plugin in the docs.
i have, it's not mentioned on there
asked here so know if there is a way to bypass it or smthn
What do you mean by not mentioned here? What are you trying to do exactly?
turn on 2FA on signup without using the user's passwd
Do you mean like to automatically turn on 2fa after sign up? Yeah i think that it could be possible with some db hook or maybe two factor plugin has some option that does that automatically
yh that's what I'm trying to do
the plugin doesn't have that option
Then create a hook that would capture the user password and call the 2fa enable