You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_partials/session-tasks-table.mdx
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,3 +6,4 @@ The following table lists the available tasks and their corresponding keys.
6
6
| - | - | - |
7
7
|[Allow Personal Accounts](/docs/guides/organizations/configure#personal-accounts)|`choose-organization`| Disabled by default when enabling Organizations [for instances created after August 22, 2025](!update). When disabled, users are required to choose an Organization after authenticating. When enabled, users can choose a [Personal Account](!personal-account) instead of an Organization. |
8
8
|[Force password reset](/docs/guides/secure/password-protection-and-rules#manually-set-a-password-as-compromised)|`reset-password`| Enabled by default [for instances created after December 8, 2025](!update). When enabled, the user is required to reset their password on their next sign-in if their password is marked as compromised. |
9
+
|[Multi-factor authentication requirement](/docs/guides/configure/auth-strategies/sign-up-sign-in-options#multi-factor-authentication)|`setup-mfa`| When enabled, users are required to set up multi-factor authentication (MFA) after authenticating. Users can choose between authenticator app (TOTP) or SMS verification depending on which methods are enabled in the instance settings. |
|`setup-mfa`|[Manage TOTP-based MFA guide](/docs/guides/development/custom-flows/account-updates/manage-totp-based-mfa) or [Manage SMS-based MFA guide](/docs/guides/development/custom-flows/account-updates/manage-sms-based-mfa){/* TODO: Update to setup-mfa custom flow guide once created */}|
@@ -3,169 +3,189 @@ title: Force multi-factor authentication (MFA) for all users
3
3
description: Learn how to force multi-factor authentication (MFA) for all users in your Clerk application.
4
4
---
5
5
6
-
By default, Clerk does not enforce [multi-factor authentication (MFA)](/docs/guides/configure/auth-strategies/sign-up-sign-in-options#multi-factor-authentication) for all users. This guide demonstrates how to force MFA for all users by using `clerkMiddleware()` to intercept all requests and check whether a user has MFA enabled. If the user does not have MFA enabled, `clerkMiddleware()` redirects them to the `/mfa`page where they can set up MFA.
6
+
Clerk can require all users to set up multi-factor authentication (MFA) after signing in or signing up. This guide demonstrates how to enable this requirement using Clerk's `setup-mfa`[session task](!session-tasks).
7
7
8
8
<Steps>
9
-
## Enable MFA in the Clerk Dashboard
9
+
## Enable MFA strategies
10
10
11
-
If you haven't already, enable MFA for your users.
11
+
First, enable the MFA strategies you want to offer to your users.
12
12
13
13
1. In the Clerk Dashboard, navigate to the [**Multi-factor**](https://dashboard.clerk.com/~/user-authentication/multi-factor) page.
14
-
1. Toggle on the MFA strategies you would like to enable.
14
+
1. Toggle on the MFA strategies you would like to enable:
15
+
-**Authenticator application (TOTP)**: Users can use apps like Google Authenticator or Authy
16
+
-**SMS verification code**: Users receive a one-time code via SMS
15
17
16
-
## Customize the session token to include the `two_factor_enabled` property
18
+
## Enable MFA requirement
17
19
18
-
Every `User` object has a `two_factor_enabled` property that indicates whether the user has MFA enabled. Store this property in the session token so that you can check it in your `clerkMiddleware()`.
20
+
Once you've enabled at least one MFA strategy, you can require all users to set up MFA.
19
21
20
-
1.In the Clerk Dashboard, navigate to the [**Sessions**](https://dashboard.clerk.com/~/sessions) page.
21
-
1.Under **Customize session token**, in the **Claims** editor, enter the following JSON and select **Save**. The key can be any string, but the value must be the `user.two_factor_enabled` property, as shown in the following example. If you have already customized your session token, you may need to merge this with what you currently have.
22
+
1.On the same [**Multi-factor**](https://dashboard.clerk.com/~/user-authentication/multi-factor) page, scroll down to the **Require multi-factor authentication** section.
23
+
1.Toggle on **Require multi-factor authentication**.
22
24
23
-
```json
24
-
{
25
-
"isMfa": "{{user.two_factor_enabled}}"
26
-
}
27
-
```
25
+
When enabled, Clerk automatically creates a `setup-mfa` session task for:
26
+
- New users after they sign up
27
+
- Existing users without MFA on their next sign-in
28
28
29
-
## Update `clerkMiddleware()`
29
+
## How it works
30
30
31
-
Update your `clerkMiddleware()` to check if the user has MFA enabled.
31
+
Once the MFA requirement is enabled:
32
32
33
-
<Tabsitems={['Next.js', 'Astro', 'Nuxt']}>
33
+
1. Users sign in or sign up successfully
34
+
1. If they don't have MFA set up, Clerk creates a `setup-mfa` session task
35
+
1. The user's session enters a `pending` state and they're treated as signed-out
36
+
1. Clerk's [`<SignIn />`](/docs/reference/components/authentication/sign-in) and [`<SignUp />`](/docs/reference/components/authentication/sign-up) components automatically display the [`<TaskSetupMfa />`](/docs/reference/components/authentication/task-setup-mfa) component
37
+
1. After the user completes MFA setup, their session becomes `active` and they can access your application
38
+
39
+
For more information about session tasks, see the [session tasks guide](/docs/guides/configure/session-tasks).
40
+
41
+
## (Optional) Customize the MFA setup page
42
+
43
+
By default, the `<SignIn />` and `<SignUp />` components handle the MFA setup flow automatically. However, if you want to customize the route where the MFA setup page is rendered, you can host the `<TaskSetupMfa />` component on a custom page.
By default, the Nuxt SDK automatically adds [the `clerkMiddleware()` helper](/docs/reference/nuxt/clerk-middleware) to your Nuxt application. To manually configure the middleware, in your `nuxt.config.ts` file, under the `clerk` property, set `skipServerMiddleware: true`.
Follow the [custom flow guide](/docs/guides/development/custom-flows/account-updates/manage-totp-based-mfa) to build the `/account/manage-mfa/add` page.
183
+
For more information about the `<TaskSetupMfa />` component, see the [component reference](/docs/reference/components/authentication/task-setup-mfa).
171
184
</Steps>
185
+
186
+
## Additional considerations
187
+
188
+
-**Existing users**: Users who already have accounts will be prompted to set up MFA on their next sign-in.
189
+
-**Custom flows**: If Clerk's prebuilt components don't meet your needs, you can build a custom MFA setup flow using the Clerk API. See the [custom flow guides](/docs/guides/development/custom-flows/account-updates/manage-totp-based-mfa) for more information.
190
+
{/* TODO: Update link to setup-mfa custom flow guide once created */}
191
+
-**Session handling**: Users with pending `setup-mfa` tasks are treated as signed-out by default. Learn more about [session tasks](/docs/guides/configure/session-tasks).
0 commit comments