Add MFA to Your Web App

Multi-factor authentication (MFA) means a stolen password is no longer enough to get into an account. The Bridge, the auth, billing and feature-flag platform for SaaS apps, ships it as a switch, with codes by SMS or from an authenticator app (TOTP): users enroll a phone or an authenticator app and confirm a code, and phone setup ends with a recovery code. After that, every sign-in method asks for a fresh code, on the hosted login page and in the in-app login box, wherever MFA is on for the app and the workspace.

GDPR compliant ISO 27001 Security audited Enterprise-grade & compliant by default

Turn on MFA for my app with The Bridge

MFA, wired in

  • MFA switched onOne setting in the Control Center, the CLI or MCP.
  • Enrollment handledUsers add a phone or an authenticator app and confirm a code at their next sign-in.
  • Recovery code issuedShown once at setup, for the day the phone is gone.
  • Same user modelThe second factor sits on the user who carries plan and flags.
One switch

Turn it on. That's the setup.

MFA is a setting, not a project. Switch it on and the next sign-in asks for a second step. With the drop-in login form there is nothing to add to your app code.

Flip it, watch your login screen update live.

Or just ask

Turn on MFA from your editor

The Bridge is agent-native. Connect your AI assistant to the remote MCP (Model Context Protocol) server and switch MFA on by asking.

✦ MCP-nativeClaude CodeCursorAny MCP client

Your agent flips the switch. You ship MFA.

Connect https://api.thebridge.dev/mcp as a remote MCP server and approve access to your app. Its update_auth_methods tool turns MFA on or off.

Why MFA

What the second factor buys you

A password can be phished, reused or leaked. With a second factor, the password alone opens nothing.

  • Passwords stop being keys

    A leaked password still needs the code from the user's phone or authenticator app.

    Security
  • Enrollment built in

    Users add a phone or an authenticator app themselves at their next sign-in.

    Onboarding
  • Recovery from day one

    Phone setup issues a recovery code, before anyone needs it.

    Support
  • One user model

    MFA lives on the same user that carries roles, plan and flags.

    Stack
And of course

First-class SDKs for every stack

Type-safe, batteries-included SDKs with drop-in components, and the same clean user object everywhere.

Next.js Next.js
Svelte Svelte
Astro Astro
Node Node
Go Go
FastAPI FastAPI
Laravel Laravel
Flutter Flutter
React React
Angular Angular
Nuxt Nuxt
Deno Deno
Python Python
Rust Rust
Ruby Ruby
Kotlin Kotlin
Vue Vue
SolidJS SolidJS
Remix Remix
Bun Bun
Django Django
PHP PHP
.NET .NET
NestJS NestJS

…and 24+ frameworks & languages supported. Hover to pause, drag or swipe to explore.

Building MFA yourself vs. The Bridge

What a hand-built second factor involves, versus one setting.

Building it yourself

  • Generate a per-user secret and encrypt it at rest
  • Integrate and pay an SMS provider to deliver codes
  • Build enrollment: QR code or phone verification, first-code confirmation, re-enrollment
  • Verify codes with a drift window and refuse replays
  • Rate-limit attempts across sessions, plus resend and SMS costs
  • Generate, hash and single-use recovery codes
  • Design account recovery that does not become the bypass

With The Bridge

  • Switch MFA on in the Control Center, the CLI or MCP
  • Phone or authenticator app enrollment handled
  • SMS codes and authenticator app codes, both verified for you
  • 5 wrong tries per texted code, and each expires after 10 minutes
  • Resend after a 60-second wait in the login box
  • Recovery code issued and verified for you
  • SMS delivery handled, no provider to integrate
Under the hood

What Adding MFA Actually Involves

What does adding MFA to a web app involve?

To add MFA to a web app, generate a per-user secret, show it as a QR code, have the user scan it with an authenticator app, and confirm one six-digit code to finish enrollment. Then require a fresh code at every login, and issue recovery codes right away so a lost phone does not lock anyone out.

That is the time-based one-time password (TOTP) path. The other common path texts the code by SMS instead of computing it in an app. Either way the shape is the same: enroll once, prove the second factor at every login, and keep a way back in. It is one layer of SaaS identity and authentication, next to sessions, roles and single sign-on.

With The Bridge, MFA is one setting in the Control Center, and both paths are offered: codes texted to the user's enrolled phone, with a recovery code as backup, or codes from an authenticator app (TOTP).

How does TOTP MFA work under the hood?

TOTP turns a shared secret and the current time into a six-digit code. The server and the user's app both hold the secret, both count 30-second steps since 1970, and both run the same hash. If the user's code matches the server's, the user has the device that holds the secret.

The math is the HMAC-based one-time password (HOTP, RFC 4226) with the clock as its counter. HOTP takes a hash-based message authentication code (HMAC) over a counter with the shared secret and truncates it to at least six digits. TOTP (RFC 6238) replaces the counter with the number of 30-second steps since the Unix epoch, so the code changes every half minute.

  • Enrollment: the server makes a random secret (RFC 4226 asks for at least 128 bits and recommends 160) and shows it as an otpauth://totp/... URI in a QR code. The user scans it with Google Authenticator or any app that supports TOTP.
  • Confirmation: the user types one code back to prove the scan worked.
  • Login: the server computes the expected code and compares. RFC 6238 recommends allowing at most one time step of network delay, and a code that has been accepted once is never accepted again.

SMS codes skip the shared secret: the server picks a random code and texts it. The Bridge's MFA offers both models: a 6-digit one-time code sent to the enrolled phone, or a code from the user's authenticator app.

What does building MFA yourself involve?

Building MFA yourself means owning a secret store, an enrollment flow, a verifier with a drift window and replay protection, rate limits, recovery codes and an account recovery process. The code check is the easy part. The rest is where the work and the security holes are.

  • Secret storage. Each user's TOTP secret is a password equivalent. RFC 4226 recommends encrypting it at rest and decrypting it only to verify a code.
  • SMS delivery. Choosing, integrating and paying a provider to text the codes.
  • Enrollment. QR generation or phone verification, a confirmation code, and re-enrollment when a user changes phones.
  • Verification. A drift window, a record of used codes so none is accepted twice, and the same check on every way into the account.
  • Rate limiting. The US National Institute of Standards and Technology (NIST) SP 800-63B caps consecutive failed attempts at 100 per authenticator. SMS adds resend limits, and the Open Worldwide Application Security Project (OWASP) warns attackers can trigger floods of messages to run up your bill.
  • Recovery codes. Generated at setup, stored hashed, single-use, and replaceable.
  • Account recovery. The flow for a user with no phone and no codes, which OWASP warns can itself become the way around MFA.

The Bridge verifies both SMS and authenticator app codes, sends the texted ones with 5 wrong tries per code and a 10-minute expiry, and issues the recovery code.

How does MFA work through The Bridge?

With The Bridge, MFA is one setting: switch it on in the Control Center under Auth, Login, or run one CLI command. Users enroll a phone for texted codes or an authenticator app (TOTP), and confirm a code. Every later sign-in asks for a fresh code, whichever way the user signs in, on the same user model as billing and flags.

Switch it on in the Control Center under Auth, Login, with bridge app update --mfa-enabled true, or through the MCP tool update_auth_methods. With the drop-in LoginForm, none of the three needs code in your app.

MFA asks for a code when it is on in two places: for the app in the Control Center, and for each workspace in the workspace's details. There it follows every sign-in method, from password and magic link to passkeys, Google, GitHub and enterprise SSO, on the hosted login page and in the in-app login box.

SMS and authenticator app codes are both offered. The first time MFA is required, the user sets up a second factor.

  • Authenticator app (TOTP): the user adds the account to an authenticator app and confirms a code from it. After that, each sign-in asks for the current code from the app.
  • SMS: the user enters a phone number, verifies the 6-digit code The Bridge texts to it, and saves a one-time recovery code. After that, each sign-in asks for a new texted code, or the recovery code if the phone is gone.

Each texted code allows 5 wrong tries and expires after 10 minutes, and each resend replaces the previous code. The login box waits 60 seconds before it offers a resend; the server doesn't enforce that wait, and there is no account lockout.

The recovery code doesn't finish the sign-in on its own. It removes the old phone and code, and the user sets up a phone again and gets a new recovery code before they are in.

The drop-in LoginForm walks through both flows inline after the password step. If you build your own screens, ready-made setup and challenge components (MfaSetup, MfaChallenge) cover the same steps in SvelteKit, Next.js, React and Angular. The full reference is in the MFA docs.

What matters once MFA is in production?

In production, MFA is decided by recovery: how a user with no phone gets back in without a support ticket becoming the bypass. Next to that, offer a phishing-resistant option alongside SMS codes, and require the second factor on every way users sign in.

  • Recovery without a backdoor. OWASP warns that any process that resets MFA can be used by an attacker. Changing a factor should require an existing factor and notify the user out of band. The recovery code is the first line here: in The Bridge, using it makes the user set up a phone again, and they get a new recovery code.
  • SMS, honestly. NIST SP 800-63B-4 lists codes sent over the phone network (SMS or voice) as its one restricted authenticator: allowed if you offer at least one unrestricted alternative, give users meaningful notice of the risk and keep a migration plan. OWASP adds that SMS is open to SIM swapping and advises against it for high-value or PII-handling apps; there, pair it with or move users to an authenticator app or passkeys, both of which The Bridge offers next to SMS. Email codes are not acceptable as an out-of-band authenticator at all.
  • A stronger factor. Passkeys are phishing-resistant because they are bound to your site's origin. The Bridge ships them next to MFA; see how to implement passkeys (WebAuthn).
  • Every entry point. OWASP asks that every way to log in requires MFA, and recommends it for sensitive actions such as disabling MFA. For per-framework wiring and route guards, see the SvelteKit auth guide.

In The Bridge, passkeys and MFA, by SMS or authenticator app, are both settings in the Control Center under Auth, Login.

Common questions

Which authenticator apps work with TOTP MFA?
Any app that supports standard TOTP (RFC 6238), such as Google Authenticator, since the enrollment QR code uses a shared format. The Bridge offers authenticator app codes alongside texted SMS codes. See the MFA docs.
What if the user's clock drifts?
TOTP verifiers accept codes from a small window around the current 30-second step; RFC 6238 recommends at most one step of network delay, and a server can record a device's measured drift. SMS codes do not depend on the phone's clock.
Should MFA run on every login or once per device?
OWASP's baseline is MFA at every login, plus extra prompts for sensitive actions and new devices or locations. The Bridge has no remember-this-device option: where MFA is on for both the app and the workspace, every sign-in asks for a fresh code. See what matters in production and the MFA docs.
Is email OTP an acceptable second factor?
Not by NIST's standard: SP 800-63B-4 says email shall not be used for out-of-band authentication, because an inbox can often be opened with a password alone, and mail can be intercepted or rerouted in transit. Use an authenticator app, SMS with its known risks, or passkeys.
Ready to

add MFA without owning the plumbing?

Switch on MFA next to passkeys, roles, billing and flags. See what each plan includes.

See pricing
Keep building

Explore every identity guide

Every auth question you were saving for later, answered in its own guide. Pick one and go build.