[GH-ISSUE #5312] Add an option to enable by default 2fa for any new user when twofactor plugin is used #27535

Open
opened 2026-04-17 18:35:50 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @gregoiregentil on GitHub (Oct 14, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5312

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

No response

Describe the solution you'd like

Please let me know if I'm mussing, something, but If the plugin twoFactor is used, there should be an option to enable by default two factor for any new user.
Right now, the API two-factor/enable should be called plus it should pass the user password.
It's not up to the user to be the only one to decide if it's going to use 2FA or not. An administrator or system-policy should enforce that.

Describe alternatives you've considered

There would be alternative via hooks but it's horrible with the requirement to pass the password for enabling 2FA.

Additional context

No response

Originally created by @gregoiregentil on GitHub (Oct 14, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5312 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [ ] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. _No response_ ### Describe the solution you'd like Please let me know if I'm mussing, something, but If the plugin twoFactor is used, there should be an option to enable by default two factor for any new user. Right now, the API two-factor/enable should be called plus it should pass the user password. It's not up to the user to be the only one to decide if it's going to use 2FA or not. An administrator or system-policy should enforce that. ### Describe alternatives you've considered There would be alternative via hooks but it's horrible with the requirement to pass the password for enabling 2FA. ### Additional context _No response_
GiteaMirror added the security label 2026-04-17 18:35:50 -05:00
Author
Owner

@Blowy commented on GitHub (Dec 7, 2025):

I totally agree - I can totally imagine users neglecting to set up 2fa if given the choice!
Would love for 2fa to be configurable as a default.

<!-- gh-comment-id:3621932920 --> @Blowy commented on GitHub (Dec 7, 2025): I totally agree - I can totally imagine users neglecting to set up 2fa if given the choice! Would love for 2fa to be configurable as a default.
Author
Owner

@aladinyo commented on GitHub (Dec 30, 2025):

yesss man, we need this so much, I agree with you

<!-- gh-comment-id:3700590526 --> @aladinyo commented on GitHub (Dec 30, 2025): yesss man, we need this so much, I agree with you
Author
Owner

@0x7s0lt1 commented on GitHub (Feb 23, 2026):

You can do something like this:


const auth = betterAuth({
	emailAndPassword: {
		enabled: true,
		autoSignIn: true
	},
})

const { headers, response } = await auth.api.signUpEmail({
    returnHeaders: true,
    body: {
        name,
        email,
        password
    },
    headers: fromNodeHeaders(req.headers),
});

headers.cookie = headers.get("set-cookie");

const twoFaData = await auth.api.enableTwoFactor({
    body: {
        password,
        issuer: "my-app",
    },
    headers: fromNodeHeaders(headers),
});

// and sign out maybe
<!-- gh-comment-id:3947772738 --> @0x7s0lt1 commented on GitHub (Feb 23, 2026): You can do something like this: ```javascript const auth = betterAuth({ emailAndPassword: { enabled: true, autoSignIn: true }, }) const { headers, response } = await auth.api.signUpEmail({ returnHeaders: true, body: { name, email, password }, headers: fromNodeHeaders(req.headers), }); headers.cookie = headers.get("set-cookie"); const twoFaData = await auth.api.enableTwoFactor({ body: { password, issuer: "my-app", }, headers: fromNodeHeaders(headers), }); // and sign out maybe ```
Author
Owner

@gregoiregentil commented on GitHub (Feb 24, 2026):

Thank you for suggesting something. Your suggestion made me click ;-) I would prefer to do a hook such as:

 after: createAuthMiddleware(async (ctx) => {
			if (ctx.path == "/sign-up/email")

get the password there and send an API call.

It's still ugly that your original idea and this one consist of catching the password in order to call the twofactor API...

<!-- gh-comment-id:3948230796 --> @gregoiregentil commented on GitHub (Feb 24, 2026): Thank you for suggesting something. Your suggestion made me click ;-) I would prefer to do a hook such as: ``` after: createAuthMiddleware(async (ctx) => { if (ctx.path == "/sign-up/email") ``` get the password there and send an API call. It's still ugly that your original idea and this one consist of catching the password in order to call the twofactor API...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27535