{
    "componentChunkName": "component---src-pages-blog-markdown-remark-fields-slug-js",
    "path": "/blog/add-mfa-to-nextjs",
    "result": {"data":{"markdownRemark":{"html":"<p>Next.js powers everything from enterprise SaaS dashboards to consumer-facing applications, making security paramount across diverse\ndeployment scenarios. A single stolen password can compromise entire systems and expose sensitive user data. According to a <a href=\"https://techcommunity.microsoft.com/blog/coreinfrastructureandsecurityblog/microsoft-will-require-mfa-for-all-azure-users/4140391#:~:text=The%20need%20for,security%20measures%20available.\" target=\"_blank\" rel=\"nofollow\">Microsoft report</a>, 99.9% of compromised accounts did not use MFA; and enabling MFA can block more than 99.2% of account compromise attacks. That means that adding MFA is one of the simplest, highest-impact ways to secure your Next.js app. And with SuperTokens, you can set it up in just a few minutes.</p>\n<h2 id=\"what-does-mfa-mean-inside-a-nextjs-project\" style=\"position:relative;\"><a href=\"#what-does-mfa-mean-inside-a-nextjs-project\" aria-label=\"what does mfa mean inside a nextjs project permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>What Does MFA Mean Inside a Next.js Project?</strong></h2>\n<p><strong><a href=\"https://supertokens.com/docs/additional-verification/mfa/introduction\" target=\"_blank\" rel=\"nofollow\">Multi-factor authentication</a></strong> <strong>(MFA)</strong> requires users to provide a second verification step beyond their primary password, typically through time-based one-time passwords (TOTP), email or SMS codes, or hardware-backed authentication methods like passkeys. This additional security layer dramatically reduces the risk of unauthorized access, even when primary credentials are compromised.</p>\n<p><strong><a href=\"https://nextjs.org/docs/architecture\" target=\"_blank\" rel=\"nofollow\">Next.js architecture</a></strong> requires careful consideration of how MFA flows integrate with modern framework features. MFA implementations must work seamlessly with App Router, edge functions, and Incremental Static Regeneration (ISR) pages, without blocking server-side rendering processes. The authentication flow needs to handle both client-side and server-side verification, while maintaining performance characteristics that users expect from Next.js applications.</p>\n<p>Authentication state management becomes particularly critical in Next.js environments where pages can render on servers, at the edge, or in browsers. MFA flows must coordinate between these different execution environments while maintaining security guarantees and providing smooth user experiences across all rendering strategies.</p>\n<h2 id=\"popular-mfa-methods-you-can-enable-in-nextjs\" style=\"position:relative;\"><a href=\"#popular-mfa-methods-you-can-enable-in-nextjs\" aria-label=\"popular mfa methods you can enable in nextjs permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Popular MFA Methods You Can Enable in Next.js</strong></h2>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/b186738e2061e24ccb294e218ead3a85/919c7/Popular-MFA-Methods-You-Can-Enable-in-Next.js.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 38.60759493670886%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAAsTAAALEwEAmpwYAAABeUlEQVQoz3VRy47iMBDkAyCO3Th+hLzMTFgQYRiN4MCX8P9HPqJq5QyDZg97KLVV3VXqai82zmBbC/e14BQNPmvDr6HCeRdxOGz4dmwxTB3aqcdmv2X7fkA/fCINF6bhgqH/QttM8H6giHssxGiIVmycResrONEMThCiRVVX9H1EmhLitoFEzyps4HxH5zoM/YTx/YIYE8RYGiOPhdEawXvWMUJrDaUUcy21hqyFPnq44BBihDFm7ulS01qHEBoURYmqclnLsiwfi9Vyydvthuv1SivCvusgIrlJMQYhBKYhsW1biggyXxQFmqbjbnfk+fzB43Ga+dmwKAqOKXH6s0PXtqidy1u8YO0a27eEWEd0fZdNZ365XOJ0mnC/3+dk2VBr/VjkR7KW2xDom5pOhOq7OW9pTEkXLJ2ztFZefDYex5F1rLkb91Cq+DbMAyuluBZD76ock+UvQ6UyFJ+RXph1qxXzXa2tnpGfG/6Ifw//1P/hX516fcpfuy/K3Z3+PfAAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Popular MFA Methods You Can Enable in Next.js\"\n        title=\"Popular MFA Methods You Can Enable in Next.js\"\n        src=\"/static/b186738e2061e24ccb294e218ead3a85/f058b/Popular-MFA-Methods-You-Can-Enable-in-Next.js.png\"\n        srcset=\"/static/b186738e2061e24ccb294e218ead3a85/c26ae/Popular-MFA-Methods-You-Can-Enable-in-Next.js.png 158w,\n/static/b186738e2061e24ccb294e218ead3a85/6bdcf/Popular-MFA-Methods-You-Can-Enable-in-Next.js.png 315w,\n/static/b186738e2061e24ccb294e218ead3a85/f058b/Popular-MFA-Methods-You-Can-Enable-in-Next.js.png 630w,\n/static/b186738e2061e24ccb294e218ead3a85/40601/Popular-MFA-Methods-You-Can-Enable-in-Next.js.png 945w,\n/static/b186738e2061e24ccb294e218ead3a85/78612/Popular-MFA-Methods-You-Can-Enable-in-Next.js.png 1260w,\n/static/b186738e2061e24ccb294e218ead3a85/919c7/Popular-MFA-Methods-You-Can-Enable-in-Next.js.png 2795w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<ul>\n<li><strong>Time-Based One-Time Passwords (TOTP)</strong> is the most widely adopted MFA method, popularized by Google Authenticator and similar applications. TOTP generates six-digit codes that refresh every 30 seconds based on shared secrets, providing offline functionality that works even without network connectivity. Users scan QR codes during setup to establish the shared secret between their authenticator app and the application.</li>\n<li><strong>Email and SMS One-Time Passcodes (OTP)</strong> offer the lowest user friction for SaaS applications since they require no additional app installations or hardware purchases. Email OTP works across all devices with email access, while SMS OTP provides immediate delivery to mobile phones. However, SMS-based authentication faces increasing security concerns due to SIM swapping attacks and carrier vulnerabilities.</li>\n<li><strong>Passkeys and WebAuthn</strong> deliver hardware-backed, phishing-proof authentication that represents the future of secure login experiences. Passkeys leverage built-in biometric sensors like fingerprints or facial recognition, providing both security and convenience. Browser support includes Chrome, Safari, Firefox, and Edge, with mobile support across iOS and Android platforms.</li>\n</ul>\n<h2 id=\"planning-mfa--4-questions-to-answer-before-you-code\" style=\"position:relative;\"><a href=\"#planning-mfa--4-questions-to-answer-before-you-code\" aria-label=\"planning mfa  4 questions to answer before you code permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Planning MFA — 4 Questions to Answer Before You Code</strong></h2>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/bffb4bdb92e40068ce24c45930d69559/37523/Planning-MFA%E2%80%944-Questions-to-Answer-Before-You-Code.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 80.37974683544303%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAAsTAAALEwEAmpwYAAACI0lEQVQ4y4WSy3bUMBBE8wfo0S3JkmXZngyTMDwC2WTHEjasWfD/v9HFaTkzTEICizp2S+6rapWvDHnYyLAlwrUMt6ug/QQ+NMRDw3BoKG8njPuKaTeirRnznLBMAetIWAeHNVms0WCJBlfWOXRoIJjEMDnAjgmuDl2+DqA6gGsCl4iQA+LAiJEQ2SGSRfLmrCtrLayzMM7BBwKlCJ8C/MCgHMElbXUK4CGCogcFDyILJgfyDs68gTMGzirQGFhrYIxBCAFpSFLGWdp8K0MZJeVBKDA8E3IZoeut3ciyfJRxXISZYI1FN2bso0NrNyAHiZFRxz0Oh6/9qTURiXMGCjoev+PD+x84vvuGdbkDkZMTQ3UJFGbGoA5LlWU5SimTpBTFe4L3XoYhd2itq9R6LTmP3aH2PgfKCVhKkXmeZRyLTJMCk3jvu8sYI3JO0tokpWSJMYhe00vAPvKp0Tl/drXVDipm1nU9oGurfe99DShEDO8dvLcg6gcoTKEK72uXe9rzKrCnnKK06Ub2+wfJufaRNxD1+9V7W9e7nrB++zjyq0AJweP6+gH3X36h5BkxBuiY2x0ypukWn+9+Yl3vEQKBObzo8ByKnqopLss7yTmfQ1Hpnv4Bu90nqXXRkHrPf1PWFFur0lp7MrK+T1N93Nv+gBD41ZTPTrZUfU/3IhT8SXz7Ruu/UtbitKDQk57V+MfznIHqSSin8Z8JF5KX9i8d/ga6X5EP3dbQWgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Planning-MFA—4-Questions-to-Answer-Before-You-Code\"\n        title=\"Planning-MFA—4-Questions-to-Answer-Before-You-Code\"\n        src=\"/static/bffb4bdb92e40068ce24c45930d69559/f058b/Planning-MFA%E2%80%944-Questions-to-Answer-Before-You-Code.png\"\n        srcset=\"/static/bffb4bdb92e40068ce24c45930d69559/c26ae/Planning-MFA%E2%80%944-Questions-to-Answer-Before-You-Code.png 158w,\n/static/bffb4bdb92e40068ce24c45930d69559/6bdcf/Planning-MFA%E2%80%944-Questions-to-Answer-Before-You-Code.png 315w,\n/static/bffb4bdb92e40068ce24c45930d69559/f058b/Planning-MFA%E2%80%944-Questions-to-Answer-Before-You-Code.png 630w,\n/static/bffb4bdb92e40068ce24c45930d69559/37523/Planning-MFA%E2%80%944-Questions-to-Answer-Before-You-Code.png 720w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p><strong>Mandatory or Step-Up Authentication?</strong> This determines whether all users must complete MFA during every login, or only for high-risk actions like financial transactions or administrative operations. Mandatory MFA provides maximum security but may create user friction, while step-up authentication balances security with usability by requiring additional verification only when accessing sensitive features.</p>\n<p><strong>Recovery Path Strategy</strong> addresses inevitable scenarios where users lose access to their MFA devices or forget backup codes. Options include issuing printable backup codes during MFA setup, allowing email-basedemergency access, or implementing administrative reset procedures for enterprise environments. Recovery mechanisms must balance user convenience with security requirements.</p>\n<p><strong>Device Remembering Policy</strong> controls whether trusted devices can bypass MFA requirements for specified periods, typically 30 days. Device remembering reduces user friction on frequently used devices while maintaining security for new or suspicious login attempts. Implementation requires secure device fingerprinting and careful consideration of security implications.</p>\n<p><strong>State Management Model</strong> determines how the authentication state persists across requests and sessions. Central session stores provide comprehensive control and real-time revocation capabilities, while stateless JWT tokens enable better scalability and edge deployment compatibility. The choice impacts performance, scalability, and security characteristics of the overall authentication system.</p>\n<h2 id=\"implementation-strategies-seen-in-the-wild\" style=\"position:relative;\"><a href=\"#implementation-strategies-seen-in-the-wild\" aria-label=\"implementation strategies seen in the wild permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Implementation Strategies Seen in the Wild</strong></h2>\n<table>\n<thead>\n<tr>\n<th>Strategy</th>\n<th>Libraries / Services</th>\n<th>Pros</th>\n<th>Cons</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>NextAuth.js + Custom 2FA</td>\n<td>next-auth + plugins</td>\n<td>Familiar to many developers, extensive community</td>\n<td>DIY secret storage requirements, limited step-up authentication</td>\n</tr>\n<tr>\n<td>AWS Amplify Authentication</td>\n<td>Cognito backend</td>\n<td>Fully hosted solution, built-in SMS and TOTP</td>\n<td>Vendor lock-in concerns, TTL configuration limits</td>\n</tr>\n<tr>\n<td>Custom Speakeasy</td>\n<td>speakeasy + QR libraries</td>\n<td>Complete implementation control</td>\n<td>High maintenance overhead, security implementation risks</td>\n</tr>\n<tr>\n<td>SuperTokens MFA</td>\n<td>Self-hosted or managed</td>\n<td>Drop-in UI components, automatic token rotation, theft detection</td>\n<td>Requires Core instance deployment (Docker or Cloud)</td>\n</tr>\n</tbody>\n</table>\n<p><strong>NextAuth.js with custom 2FA</strong> leverages familiar developer patterns but requires manual implementation of secret storage, backup codes, and step-up authentication flows. While the initial setup feels straightforward, production-grade security features require significant\nadditional development.</p>\n<p><a href=\"https://aws.amazon.com/amplify/authentication/\" target=\"_blank\" rel=\"nofollow\">AWS Amplify Authentication</a> provides comprehensive hosting through Cognito but creates vendor dependencies that may limit future flexibility. The platform includes built-in SMS and TOTP support with enterprise-grade scaling, though configuration options can be restrictive for complex authentication\nrequirements.</p>\n<p><strong>Custom implementation by using Speakeasy</strong> offers maximum control over authentication flows and user experience, but requires expertise in cryptographic operations, secure secret management, and vulnerability prevention. The maintenance burden grows significantly as security\nrequirements evolve.</p>\n<p><a href=\"https://supertokens.com/\" target=\"_blank\" rel=\"nofollow\">SuperTokens</a> <strong>MFA</strong> delivers production-ready authentication with minimal configuration, while supporting both self-hosted and managed deployment options. The solution includes advanced security features like automatic token rotation and theft detection that would require substantial custom development.</p>\n<h2 id=\"step-by-step-mfa-integration-with-supertokens-nextjs-app-router\" style=\"position:relative;\"><a href=\"#step-by-step-mfa-integration-with-supertokens-nextjs-app-router\" aria-label=\"step by step mfa integration with supertokens nextjs app router permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Step-by-Step MFA Integration with SuperTokens (Next.js App Router)</strong></h2>\n<p><strong>1. Deploy SuperTokens Core</strong> by using Docker for local development or the free managed trial for production testing:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"25675116068740424000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`  docker run -p 3567:3567 -d supertokens/supertokens-postgresql`, `25675116068740424000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">  docker run <span class=\"token operator\">-</span>p <span class=\"token number\">3567</span><span class=\"token operator\">:</span><span class=\"token number\">3567</span> <span class=\"token operator\">-</span>d supertokens<span class=\"token operator\">/</span>supertokens<span class=\"token operator\">-</span>postgresql</code></pre></div>\n<p><strong>2. Install Required SDKs</strong> for both backend and frontend integration:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"56455786745935610000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`  npm install supertokens-node supertokens-auth-react`, `56455786745935610000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">  npm install supertokens<span class=\"token operator\">-</span>node supertokens<span class=\"token operator\">-</span>auth<span class=\"token operator\">-</span>react</code></pre></div>\n<p><strong>3. Configure Authentication Recipes</strong> in your Next.js API route at <code class=\"language-text\">app/api/auth/\\[\\...route\\]/route.ts</code>:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"24969970379713050000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(` import EmailPassword from \\&quot;supertokens-node/recipe/emailpassword\\&quot;;  \n import TOTP from \\&quot;supertokens-node/recipe/totp\\&quot;;                                                                    \n import MultiFactorAuth from                                           \n \\&quot;supertokens-node/recipe/multifactorauth\\&quot;;                    \n // Recipe configuration                                                                     \n EmailPassword.init(); // Primary authentication                          \n TOTP.init(); // Secondary factor                                                                       \n MultiFactorAuth.init({                                                \n firstFactors: \\[\\&quot;emailpassword\\&quot;\\],                                                                      \n getMFARequirementsForAuth: () =\\> \\[\\&quot;totp\\&quot;\\]                       \n });`, `24969970379713050000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"> <span class=\"token keyword\">import</span> EmailPassword from \\\"supertokens<span class=\"token operator\">-</span>node<span class=\"token operator\">/</span>recipe<span class=\"token operator\">/</span>emailpassword\\\"<span class=\"token punctuation\">;</span>  \n <span class=\"token keyword\">import</span> <span class=\"token constant\">TOTP</span> from \\\"supertokens<span class=\"token operator\">-</span>node<span class=\"token operator\">/</span>recipe<span class=\"token operator\">/</span>totp\\\"<span class=\"token punctuation\">;</span>                                                                    \n <span class=\"token keyword\">import</span> MultiFactorAuth from                                           \n \\\"supertokens<span class=\"token operator\">-</span>node<span class=\"token operator\">/</span>recipe<span class=\"token operator\">/</span>multifactorauth\\\"<span class=\"token punctuation\">;</span>                    \n <span class=\"token comment\">// Recipe configuration                                                                     </span>\n EmailPassword<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Primary authentication                          </span>\n <span class=\"token constant\">TOTP</span><span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Secondary factor                                                                       </span>\n MultiFactorAuth<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>                                                \n <span class=\"token literal-property property\">firstFactors</span><span class=\"token operator\">:</span> \\<span class=\"token punctuation\">[</span>\\\"emailpassword\\\"\\<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>                                                                      \n <span class=\"token literal-property property\">getMFARequirementsForAuth</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span>\\<span class=\"token operator\">></span> \\<span class=\"token punctuation\">[</span>\\\"totp\\\"\\<span class=\"token punctuation\">]</span>                       \n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>4. Protect Pages and APIs</strong> by using SuperTokens middleware to verify both session validity and MFA completion claims:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"83099669024325240000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(` import { verifySession } from                                         \n \\&quot;supertokens-node/recipe/session/framework/express\\&quot;;                \n import { withTenantId } from                                          \n \\&quot;supertokens-node/recipe/multitenancy\\&quot;;                                                                    \n // Protect API routes                             \n app.post(\\'/api/protected\\', verifySession(), (req, res) =\\> {                                                                       \n // Verified user with completed MFA                                                \n });                                                                      `, `83099669024325240000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"> <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> verifySession <span class=\"token punctuation\">}</span> from                                         \n \\\"supertokens<span class=\"token operator\">-</span>node<span class=\"token operator\">/</span>recipe<span class=\"token operator\">/</span>session<span class=\"token operator\">/</span>framework<span class=\"token operator\">/</span>express\\\"<span class=\"token punctuation\">;</span>                \n <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> withTenantId <span class=\"token punctuation\">}</span> from                                          \n \\\"supertokens<span class=\"token operator\">-</span>node<span class=\"token operator\">/</span>recipe<span class=\"token operator\">/</span>multitenancy\\\"<span class=\"token punctuation\">;</span>                                                                    \n <span class=\"token comment\">// Protect API routes                             </span>\n app<span class=\"token punctuation\">.</span><span class=\"token function\">post</span><span class=\"token punctuation\">(</span>\\'<span class=\"token operator\">/</span>api<span class=\"token operator\">/</span><span class=\"token keyword\">protected</span>\\'<span class=\"token punctuation\">,</span> <span class=\"token function\">verifySession</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>req<span class=\"token punctuation\">,</span> res<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span>\\<span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>                                                                       \n <span class=\"token comment\">// Verified user with completed MFA                                                </span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                                                      </code></pre></div>\n<p><strong>5. Frontend Integration</strong> automatically injects TOTP setup and verification screens:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"33681115387542905000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`import TOTP from \\&quot;supertokens-auth-react/recipe/totp\\&quot;;              \n // Frontend recipe initialization                                                                       \n  TOTP.init();                                   \n // Auto-generates UI at /auth/mfa/totp                                                                      `, `33681115387542905000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> <span class=\"token constant\">TOTP</span> from \\\"supertokens<span class=\"token operator\">-</span>auth<span class=\"token operator\">-</span>react<span class=\"token operator\">/</span>recipe<span class=\"token operator\">/</span>totp\\\"<span class=\"token punctuation\">;</span>              \n <span class=\"token comment\">// Frontend recipe initialization                                                                       </span>\n  <span class=\"token constant\">TOTP</span><span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                   \n <span class=\"token comment\">// Auto-generates UI at /auth/mfa/totp                                                                      </span></code></pre></div>\n<p><strong>6. Test Security Features,</strong> including token rotation and theft detection:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"74639621264737340000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(` // Token theft detection hook                                         \n Session.init({                                                                       \n  onTokenTheftDetected: (sessionHandle, userId) =\\> {                                                    \n // Log security incident                                              \n   console.log(\\'Token theft detected:\\', { sessionHandle, userId });    \n }});  `, `74639621264737340000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"> <span class=\"token comment\">// Token theft detection hook                                         </span>\n Session<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>                                                                       \n  <span class=\"token literal-property property\">onTokenTheftDetected</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>sessionHandle<span class=\"token punctuation\">,</span> userId<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span>\\<span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>                                                    \n <span class=\"token comment\">// Log security incident                                              </span>\n   console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>\\'Token theft detected<span class=\"token operator\">:</span>\\'<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> sessionHandle<span class=\"token punctuation\">,</span> userId <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    \n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  </code></pre></div>\n<h2 id=\"security-best-practices-for-nextjs--mfa\" style=\"position:relative;\"><a href=\"#security-best-practices-for-nextjs--mfa\" aria-label=\"security best practices for nextjs  mfa permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Security Best Practices for Next.js + MFA</strong></h2>\n<ul>\n<li><strong>Rotate Refresh Tokens on Every Use</strong> to invalidate stolen tokens immediately and minimize exposure windows. Automatic token rotation ensures that even if attackers obtain refresh tokens through various attack vectors, the tokens become useless after the legitimate user’s next session refresh.</li>\n<li><strong>Use Secure Cookie Configuration</strong> with HttpOnly, Secure, and SameSite=Lax attributes for all session cookies. HttpOnly prevents JavaScript access to session tokens, Secure ensures HTTPS-only transmission, and SameSite protection prevents cross-site request forgery attacks.</li>\n<li><strong>Implement Short Access Token TTLs</strong> of 15 minutes or less while relying on silent refresh mechanisms to maintain user sessions. Short-lived access tokens limit the impact of token compromise, while automatic refresh maintains seamless user experiences.</li>\n<li><strong>Edge-Runtime Friendly Session Verification</strong> enables authentication checks in middleware before requests reach API routes. This approach improves performance and security by preventing unauthorized requests from consuming backend resources.</li>\n<li><strong>Log and Alert on Token Theft Detection</strong> to provide Security Operations Center (SOC) visibility into potential security incidents. Real-time alerting enables rapid response to credential compromise attempts and helps identify attack patterns.</li>\n</ul>\n<h2 id=\"how-supertokens-gives-you-an-edge\" style=\"position:relative;\"><a href=\"#how-supertokens-gives-you-an-edge\" aria-label=\"how supertokens gives you an edge permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>How SuperTokens Gives You an Edge</strong></h2>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/7a5b39f337d72ef228443406da718b45/14747/Supertokens.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 46.202531645569614%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB90lEQVQoz1WR2W7aQABFURs84/Es3o2xMWAnQNrSkqShCwVK1ywP6e/la08VWlXqw9V9ukdXOr03bcb7ecHVcsa8m5BEjjB0VEXOuMhY1CXzYcF5VdDmCZNBzrDIKfKcLMuI44TVasXj4yMXFxf0XoxC2oGhTg15pAlNgNUBiVYsypy3TcnnJmN32vCua+iymNhotLEo7VDG4Qca6Suk9OnNS8M405RxQGIVJvAJfEnuDFezjg9nE34uGr4tF2zOzzgfVYTa4usIYRKESZEmxg/sH+BpYagS/RcmUb6P1+9TxBG/bm+432/5cn3Jw2HHzfYjm/WaJC15HsSIsES4EukGCB3TFz69aabJwwAbSKTwMFqzXq/ZbjZcLl9yd9jz8P3A3f4Tt4c9++2Orz/uWV7vOHEjRDLGcyU2rXFRSq+KAkKt8KVAComQgiiKGNUVozJjMa1ZdjWv2opFO6JtOwajU+ygw0umiLTlmc4ZdSu6s9f0MqvQykcIgZTy2J7Xx2lFEVvq1DHOHU1mqVJHGjkCm9C3A0TcHPNcZ1STGdO2o/c0VL78B3yKLyWROCGPQib1kHFV0jU1TTUkkh5WKYTN8GyBsDmeTlA2OdruPUnwpfzvoZICpwSJkQwjn1kVMy0Mg1CSGokN1NGqCEJE4BDKIpU+bn8DmczlvNDPBvIAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"SuperTokens\"\n        title=\"SuperTokens\"\n        src=\"/static/7a5b39f337d72ef228443406da718b45/f058b/Supertokens.png\"\n        srcset=\"/static/7a5b39f337d72ef228443406da718b45/c26ae/Supertokens.png 158w,\n/static/7a5b39f337d72ef228443406da718b45/6bdcf/Supertokens.png 315w,\n/static/7a5b39f337d72ef228443406da718b45/f058b/Supertokens.png 630w,\n/static/7a5b39f337d72ef228443406da718b45/40601/Supertokens.png 945w,\n/static/7a5b39f337d72ef228443406da718b45/78612/Supertokens.png 1260w,\n/static/7a5b39f337d72ef228443406da718b45/14747/Supertokens.png 1914w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>Implementing MFA in Next.js can be complex, with trade-offs between security and usability. <a href=\"https://supertokens.com/\" target=\"_blank\" rel=\"nofollow\">SuperTokens</a> simplifies this by delivering a complete solution that integrates smoothly and enforces best practices out of the box.</p>\n<ul>\n<li><a href=\"https://supertokens.com/blog/how-to-use-supertokens-pre-built-ui-with-vuejs\" target=\"_blank\" rel=\"nofollow\">Drop-In UI Components</a> eliminate custom CSS development while providing easily themeable interfaces that integrate seamlessly with existing design systems. The pre-built components handle complex authentication flows, including error states, loading indicators, and accessibility requirements.</li>\n<li><strong>Flexible Policy Engine</strong> enables both global MFA enforcement and granular step-up authentication per route by using claim validators. This flexibility supports diverse security requirements from consumer applications to enterprise systems with varying risk profiles.</li>\n<li><strong>Built-In Token Theft Detection and Rotation</strong> provides session resilience against sophisticated attack vectors, including token replay attacks, session fixation, and credential stuffing. The system automatically detects suspicious patterns and takes protective actions without user intervention.</li>\n<li><a href=\"https://supertokens.com/blog/adding-login-to-your-nextjs-app-using-the-app-directory-and-supertokens\" target=\"_blank\" rel=\"nofollow\">First-Class Next.js Support</a> ensures compatibility with App Router, edge middleware, ISR, and API routes across all deployment scenarios. The integration handles server-side rendering, client-side hydration, and edge execution environments seamlessly.</li>\n<li><strong>Open Source and Self-Hostable</strong> architecture meets compliance requirements without vendor lock-in concerns. Organizations can audit the complete authentication stack while maintaining control over data residency and security policies.</li>\n</ul>\n<h2 id=\"common-pitfalls--and-how-to-avoid-them\" style=\"position:relative;\"><a href=\"#common-pitfalls--and-how-to-avoid-them\" aria-label=\"common pitfalls  and how to avoid them permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Common Pitfalls — and How to Avoid Them</strong></h2>\n<p>Even well-planned MFA setups can fail if common mistakes are overlooked. The points below outline frequent errors in Next.js projects and how SuperTokens helps mitigate them:</p>\n<ul>\n<li><strong>Plain-Text TOTP Secrets</strong> create catastrophic security vulnerabilities that expose all user accounts to compromise. <a href=\"https://supertokens.com/\" target=\"_blank\" rel=\"nofollow\">SuperTokens</a> handles secret encryption automatically, but custom implementations must use proper encryption with secure key management practices.</li>\n<li><strong>Skipping CSRF Checks on OTP APIs</strong> enables cross-site request forgery attacks that can bypass MFA protections. Built-in middleware enforces anti-CSRF tokens automatically, but disabling these protections for convenience creates serious security gaps.</li>\n<li><strong>Long-Lived JWTs</strong> undermine MFA session safety by providing extended access even after MFA devices are compromised. Resist the temptation to use long-lived tokens for convenience, because they create security risks that far outweigh operational benefits.</li>\n<li><strong>Inadequate Recovery Planning</strong> leaves users permanently locked out when MFA devices are lost or damaged. Implement secure recovery mechanisms during initial planning rather than adding them reactively after user complaints.</li>\n</ul>\n<h2 id=\"future-proofing-your-mfa-stack\" style=\"position:relative;\"><a href=\"#future-proofing-your-mfa-stack\" aria-label=\"future proofing your mfa stack permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Future-Proofing Your MFA Stack</strong></h2>\n<p>MFA is shifting rapidly toward passwordless and adaptive models. These trends show how to keep your Next.js implementation resilient and ready for what comes next:</p>\n<ul>\n<li><strong>Passkeys Everywhere</strong> represent the inevitable evolution toward passwordless authentication. SuperTokens beta-supports FIDO2/WebAuthn flows today, preparing applications for the passwordless future as browser and operating system support expands.</li>\n<li><strong>Risk-Based Adaptive MFA</strong> leverages IP addresses, geographic locations, and device telemetry to dynamically trigger step-up authentication flows dynamically. This approach balances security with user experience by requiring additional verification only when risk indicators suggest potential threats.</li>\n<li><strong>Zero-Trust Edge Enforcement</strong> combines SuperTokens authentication claims with service mesh policies, to secure micro-frontend architectures and distributed applications. This pattern enables fine-grained access control across complex application topologies.</li>\n<li><strong>Emerging Threat Response</strong> requires authentication systems that can quickly adapt to new attack vectors and security requirements. Flexible authentication platforms enable rapid deployment of new security measures as threats evolve.</li>\n</ul>\n<h2 id=\"conclusion--ship-mfa-the-smart-way-in-nextjs\" style=\"position:relative;\"><a href=\"#conclusion--ship-mfa-the-smart-way-in-nextjs\" aria-label=\"conclusion  ship mfa the smart way in nextjs permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Conclusion — Ship MFA the Smart Way in Next.js</strong></h2>\n<p>Adding multi-factor authentication to Next.js applications shouldn’t require weeks of complex authentication infrastructure development and security expertise. With <a href=\"https://supertokens.com/\" target=\"_blank\" rel=\"nofollow\">SuperTokens</a>, development teams can implement production-ready TOTP, email/SMS OTP, or passkey authentication in hours rather than months.</p>\n<p>SuperTokens’ comprehensive solution includes advanced security features like automatic token rotation, theft detection, and polished user interfaces that would otherwise require substantial custom development. This approach enables teams to focus on core product features while ensuring enterprise-grade security standards.</p>\n<p><em><strong>Start with <a href=\"https://supertokens.com/\" target=\"_blank\" rel=\"nofollow\">SuperTokens</a> today to ship secure, user-friendly MFA that protects your Next.js applications and users from the growing threat of account compromise attacks.</strong></em></p>","frontmatter":{"date":"September 20, 2025","title":"Add MFA to Next.js in Minutes by Using SuperTokens","cover":"add-mfa-to-nextjs.png","author":"Mostafa Ibrahim","description":"Secure your Next.js app with multi-factor authentication fast. Learn how to add TOTP, email/SMS OTP, or passkeys using SuperTokens’ built-in MFA support."},"fields":{"slug":"/add-mfa-to-nextjs/"}},"site":{"siteMetadata":{"title":"SuperTokens Blog"}}},"pageContext":{"id":"f0baa0d0-ab86-5bf8-ae42-fb33372f98af","fields__slug":"/add-mfa-to-nextjs/","__params":{"fields__slug":"add-mfa-to-nextjs"}}},
    "staticQueryHashes": []}