Two-factor sign-in for your app's users
How your users can protect their accounts with an authenticator app, and how you test and reset it.
Your project's authentication supports two-factor sign-in with an authenticator app. Your app builds the screens, and the project does the checking. Once a user turns it on, a correct password alone is no longer enough.
How it works for a user
- Enrol: the signed-in user asks to turn it on. Your app calls
enrollMfa()and receives asecretand aprovisioning_uri. Show the URI as a QR code so the user can scan it with an authenticator app. - Confirm: the user enters the current 6-digit code. Your app calls
confirmMfa({ code }). The response contains backup codes, shown once. Ask the user to keep them somewhere safe. - Sign in: from now on,
signInreturnsmfa_required: trueand achallenge_tokeninstead of a session. Your app asks for a code and callsverifyMfa({ challengeToken, code })to receive the session. - Turn off:
disableMfa({ code }).
const login = await pgb.auth.signIn({ email, password });
if (login.mfa_required) {
await pgb.auth.verifyMfa({ challengeToken: login.challenge_token!, code: "123456" });
}
The challenge is short-lived (five minutes). The same calls exist in the Python, Go and Rust SDKs (verify_mfa, VerifyMFA).
Test it in the Console
Open Authentication > Auth Playground and choose the Two-factor tab. You can check a test account's status, start enrolment, confirm with a current code, and verify a sign-in challenge. The Playground uses real accounts, so use a test user.
When a user loses their device
Backup codes are the first answer: each works once. If the user has none left, open the user in Authentication, choose Manage, then Remove two-factor and confirm. They can sign in with a password again and enrol a new device.
The Manage panel shows Two-factor on or Two-factor off next to each user, so you can see who has it enabled.
Good to know
- The Console does not force two-factor for your users. You decide whether your app offers it or requires it.
- Two-factor protects password sign-ins. Always keep your own Console account protected too.
- Removing someone's two-factor is recorded in their sign-in events.
More guides in Console: authentication
Authentication in your project: users, settings and the Playground
What built-in authentication gives your app, and a tour of the Authentication page in the Console.
Choose sign-in methods and password rules
Turn sign-in methods on or off, set password rules and session lifetimes, and decide whether email must be verified.
Email verification and password reset
How confirmation emails and password resets work, and how to wire the links into your app.
Customize the emails your users receive
Edit the subject, wording, sender name and button colour of sign-in, verification and reset emails, with a live preview.
Send authentication emails from your own domain
Add and verify a sending domain so sign-in, verification and reset emails show your brand and address.
Add social login with Google or GitHub
Register your app with a provider, paste its credentials into the Console, and let people sign in with an account they already have.