Skip to content

Commit 306e378

Browse files
committed
wip: add draft fixes
1 parent 62ec845 commit 306e378

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

content/mfa-react/index.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ category: "react, mfa, guide"
77
author: "Maurice Saldivar"
88
---
99

10-
## Add MFA to React Fast with SuperTokens
10+
## Add MFA to React Fast by using SuperTokens
1111

12-
Passwords alone aren't enough. Credential stuffing attacks, phishing campaigns, and database breaches mean that even strong passwords end up in attacker hands. Multi-factor authentication addresses this by requiring a second verification step that attackers can't easily replicate.
12+
Passwords alone aren't enough. Credential-stuffing attacks, phishing campaigns, and database breaches mean that even strong passwords end up in the hands of attackers. Multi-factor authentication addresses this by requiring a second verification step, which attackers can't easily replicate.
1313

14-
The challenge for React developers: building MFA flows from scratch involves token management, session state, UI routing for factor challenges, and recovery mechanisms. SuperTokens provides pre-built MFA recipes that handle these complexities, letting you add strong second-factor security with minimal custom code.
14+
The challenge for React developers: building MFA flows from scratch involves token management, session state, UI routing for factor challenges, and recovery mechanisms. The solution: SuperTokens provides pre-built MFA recipes that handle these complexities, letting you add strong second-factor security with minimal custom code.
1515

1616
## What Is MFA in a React Context?
1717

18-
MFA requires users to prove their identity through multiple independent factors before granting access. After the primary login, users complete a second verification step using something they have (an authenticator app), something they know (a one-time code), or something they are (biometrics).
18+
MFA requires users to prove their identity through multiple independent factors before granting access. After the primary login, users complete a second verification step by using something they have (an authenticator app), something they know (a one-time code), or something they are (biometrics).
1919

2020
### How React Apps Handle MFA Flows
2121

@@ -37,23 +37,23 @@ Backend validates factor, upgrades session
3737
User accesses protected routes
3838
```
3939

40-
SuperTokens handles this coordination through its React SDK. Pre-built UI components manage factor setup and verification, while hooks let you check whether MFA is complete before rendering protected content. React components send user input to SuperTokens endpoints and render appropriate UI based on authentication state. Cryptographic operations stay server-side where they belong.
40+
SuperTokens handles this coordination through its React SDK. Pre-built UI components manage factor setup and verification, while hooks let you check whether MFA is complete before rendering protected content. React components send user input to SuperTokens endpoints, and then render the appropriate UI based on the authentication state. Cryptographic operations stay server-side where they belong.
4141

4242
## Key MFA Methods You Can Enable with SuperTokens
4343

4444
SuperTokens supports three second-factor options, each with distinct trade-offs for security and user experience.
4545

4646
**Time-Based One-Time Passwords (TOTP)**
4747

48-
Users scan a QR code with an authenticator app like Google Authenticator or Authy. The app generates 6-digit codes that refresh every 30 seconds. Both the app and your server calculate codes from a shared secret, so verification works offline without network dependencies. TOTP suits technical users comfortable managing authenticator apps and provides strong security without per-verification costs.
48+
Users scan a QR code with an authenticator app like Google Authenticator or Authy. The app generates six-digit codes that refresh every 30 seconds. Both the app and your server calculate codes from a shared secret, so verification works offline without network dependencies. TOTP suits technical users who are comfortable managing authenticator apps and TOTP provides strong security without per-verification costs.
4949

5050
**Email/SMS One-Time Passcodes (OTP)**
5151

52-
The server sends a temporary code to the user's verified email or phone number. Zero app installation required, making this the lowest-friction option for consumer SaaS products. The trade-off: each verification requires network delivery, and SMS is vulnerable to SIM-swapping attacks. Email OTP offers better security than SMS while maintaining accessibility for non-technical users.
52+
The server sends a temporary code to the user's verified email or phone number. There is zero app installation required, making this the lowest-friction option for consumer SaaS products. The trade-off: each verification requires network delivery, and SMS is vulnerable to SIM-swapping attacks. Email OTP offers better security than SMS, while maintaining accessibility for non-technical users.
5353

5454
**Passkeys/WebAuthn**
5555

56-
Hardware-backed authentication using security keys or device biometrics. The browser handles cryptographic verification with credentials bound to specific origins, providing phishing resistance that TOTP and OTP lack. When a user registers a passkey, their device generates a key pair. The private key never leaves the hardware. SuperTokens supports passkeys through its WebAuthn recipe, though adoption remains early compared to TOTP.
56+
Hardware-backed authentication by using security keys or device biometrics. The browser handles cryptographic verification with credentials bound to specific origins, providing phishing resistance that TOTP and OTP lack. When a user registers a passkey, their device generates a key pair. The private key never leaves the hardware. SuperTokens supports passkeys through its WebAuthn recipe, though adoption remains early compared to TOTP.
5757

5858
The method you choose depends on your user base. Enterprise applications with security-conscious users lean toward TOTP or passkeys. Consumer products prioritizing conversion often start with email OTP.
5959

@@ -63,7 +63,7 @@ Before writing code, answer these architectural questions. Changing MFA policy a
6363

6464
**Mandatory vs. Step-Up MFA**
6565

66-
Should all logins require a second factor, or only high-risk actions? Mandatory MFA provides consistent security but adds friction to every authentication. Step-up MFA lets users browse freely, then triggers factor verification for sensitive operations like password changes, payment modifications, or admin actions. SuperTokens supports both models through claim validators that check MFA completion on specific routes.
66+
Should all logins require a second factor, or only high-risk actions? Mandatory MFA provides consistent security, but adds friction to every authentication. Step-up MFA lets users browse freely, then triggers additional verification for sensitive operations like password changes, payment modifications, or admin actions. SuperTokens supports both models through claim validators that check MFA completion on specific routes.
6767

6868
**Recovery Mechanism**
6969

@@ -75,7 +75,7 @@ Requiring MFA on every login from the same device frustrates users. Device trust
7575

7676
**Scaling and Latency**
7777

78-
MFA verification adds a round-trip to your auth flow. For large user bases, consider where session state lives. Centralized session stores (Redis, database) enable instant revocation but add latency. Stateless JWTs reduce database calls but complicate mid-session revocation. SuperTokens supports both patterns, with built-in token theft detection that works across either architecture.
78+
MFA verification adds a round-trip to your auth flow. For large user bases, consider where the session state lives. Centralized session stores (Redis, database) enable instant revocation, but add latency. Stateless JWTs reduce database calls, but complicate mid-session revocation. SuperTokens supports both patterns, with built-in token theft detection that works across either architecture.
7979

8080
## Step-by-Step Integration Overview
8181

@@ -113,7 +113,7 @@ recipeList: [
113113

114114
**4. Wire the Frontend SDK**
115115

116-
Initialize SuperTokens in your React app. Pre-built UI components for login, factor setup, and verification auto-mount under `/auth`. Users see TOTP QR codes and input fields without custom component work.
116+
Initialize SuperTokens in your React app. The pre-built UI components for login, factor setup, and verification auto-mount under `/auth`. Users see TOTP QR codes and input fields,without custom component work.
117117

118118
**5. Protect Routes with SessionAuth**
119119

@@ -133,7 +133,7 @@ Single-use refresh tokens nullify stolen credentials. If an attacker captures a
133133

134134
**Use Secure, HttpOnly Cookies**
135135

136-
Store tokens in cookies with `Secure`, `HttpOnly`, and `SameSite` attributes. This prevents JavaScript access (blocking XSS extraction) and ensures transmission only over HTTPS. Avoid localStorage for authentication tokens in browser environments.
136+
Store tokens in cookies by using the `Secure`, `HttpOnly`, and `SameSite` attributes. This prevents JavaScript access (blocking XSS extraction) and ensures transmission only over HTTPS. Avoid localStorage for authentication tokens in browser environments.
137137

138138
**Set Short Access Token TTLs**
139139

@@ -161,7 +161,7 @@ Claim validators let you require MFA globally or on specific routes. Protect adm
161161

162162
**Built-In Token Theft Detection**
163163

164-
When refresh tokens rotate, SuperTokens tracks expected values. If an attacker replays a stolen token while the legitimate user continues their session, the system detects the conflict and revokes all sessions for that user. No custom implementation required.
164+
When refresh tokens rotate, SuperTokens tracks expected values. If an attacker uses a stolen token while the legitimate user continues their session, the system detects the conflict and revokes all sessions for that user. No custom implementation required.
165165

166166
**Pluggable Factors**
167167

@@ -177,11 +177,11 @@ MFA integration touches more than just login screens. Consider how your architec
177177

178178
**SSR and Next.js**
179179

180-
Server-side rendering requires session verification on both client and server. The SuperTokens Next.js SDK handles this by checking sessions during server rendering and hydrating state on the client. Without proper SSR support, users see authentication flickers or incorrect UI states on initial page loads. Middleware integration lets you protect routes at the edge before rendering begins.
180+
Server-side rendering (SSR) requires session verification on both the client and server. The SuperTokens Next.js SDK handles this by checking sessions during server rendering and hydrating state on the client. Without proper SSR support, users see authentication flickers or incorrect UI states on initial page loads. Middleware integration lets you protect routes at the edge before rendering begins.
181181

182182
**Microservices Architecture**
183183

184-
In service-mesh deployments, each service needs to validate tokens without calling SuperTokens Core on every request. JWTs enable local validation using public keys, while Core remains the authority for revocation. When a session is revoked, services continue accepting the token until TTL expiration. Balance TTL length against your revocation latency requirements.
184+
In service-mesh deployments, each service needs to validate tokens without calling SuperTokens Core on every request. JWTs enable local validation by using public keys, while Core remains the authority for revocation. When a session is revoked, services continue accepting the token until TTL expiration. Balance TTL length against your revocation latency requirements.
185185

186186
**Analytics and A/B Testing**
187187

@@ -197,11 +197,11 @@ TOTP secrets are equivalent to passwords. If an attacker accesses your database,
197197

198198
**Skipping CSRF Protection on OTP Endpoints**
199199

200-
OTP verification endpoints accept a code and upgrade session privileges. Without CSRF protection, an attacker who knows a user's OTP (via social engineering or interception) can submit it from a malicious site using the user's existing session cookie. SuperTokens includes anti-CSRF middleware by default. Don't disable it to "simplify" development.
200+
OTP verification endpoints work by accepting a code and upgrading session privileges. Without CSRF protection, an attacker who knows a user's OTP (via social engineering or interception) can submit it from a malicious site by using the user's existing session cookie. SuperTokens includes anti-CSRF middleware by default. Don't disable it to "simplify" development.
201201

202202
**Long-Lived JWTs**
203203

204-
Extended token lifetimes feel convenient but defeat MFA's purpose. If an attacker captures a JWT valid for 24 hours, they have 24 hours of access regardless of MFA. The user can't revoke the session until expiration. Keep access tokens short (15 minutes or less) and use refresh token rotation. The minor latency cost of frequent refreshes is worth the security gain.
204+
Extended token lifetimes feel convenient but defeat MFA's purpose. If an attacker captures a JWT valid for 24 hours, they have 24 hours of access, regardless of MFA. The user can't revoke the session until expiration. Keep access tokens short (15 minutes or less) and use refresh token rotation. The minor latency cost of frequent refreshes is worth the security gain.
205205

206206
## Future-Proofing Your MFA Stack
207207

@@ -217,7 +217,7 @@ Static MFA policies treat every login identically. Adaptive approaches analyze s
217217

218218
**Zero-Knowledge Proof Factors**
219219

220-
Emerging standards explore verification without revealing underlying data. A user could prove they possess a valid credential without transmitting the credential itself. These protocols remain experimental, but privacy regulations may drive adoption. Choosing an open-source, extensible auth platform keeps your options open as standards mature.
220+
Emerging standards explore verification without revealing underlying data. A user could prove they possess a valid credential without transmitting the credential itself. These protocols remain experimental, but privacy regulations may drive adoption. Choosing an open-source, extensible auth platform keeps your options open as standards evolve.
221221

222222
## Conclusion: Ship MFA the Smart Way
223223

@@ -227,4 +227,4 @@ Building MFA from scratch means handling TOTP secret encryption, token rotation,
227227

228228
Start with the factor that fits your users: TOTP for technical audiences, email OTP for consumer products, passkeys for security-forward applications. Plan your recovery mechanism before launch. Keep tokens short-lived and rotate them on every refresh.
229229

230-
The SuperTokens documentation includes complete integration guides for React, Next.js, and backend frameworks. If you've followed along with this overview, you have the conceptual foundation. The implementation is straightforward from here.
230+
SuperTokens documentation includes complete integration guides for React, Next.js, and backend frameworks. If you've followed along with this overview, you have the conceptual foundation. The implementation is straightforward from here.

0 commit comments

Comments
 (0)