Gate Users Until They Verify Their Email

On this page

FusionAuth 1.27.0 and later can gate a user's account until the user verifies an email address. A gated user can start the login process. The user can't finish login until the user proves ownership of the email address from registration.

To turn on email verification gating:

  1. Configure the Tenant's email server.
  2. Turn on email verification gating in the Tenant.
  3. When you want to change the verification email, customize the email verification template.
  4. Turn on self-service registrationA feature that lets users create their own accounts. in the Application.
  5. Add a redirect URLThe URL where the authorization server sends the browser after login, with an authorization code or an error. to the Application.
  6. Test the gate.

Prerequisites#

Starter plan required

This feature requires at least a Starter plan.

You need the following:

  • FusionAuth 1.27.0 or later. To install FusionAuth, see Install. To update an instance, see Update FusionAuth.
  • A paid plan and a license. To buy a plan, see Pricing. To activate an instance, see Licensing.
  • An SMTP server. To test locally, use a mock email server such as MailCatcher.

Gating, Verification, and Pre-Verification#

Email verification and registration verification are available on every plan. Gating requires a paid plan.

Email verification updates verified and verifiedReason on the user's email identity. Registration verification updates the same fields on the user's registration. Your application code can check these fields and block an unverified user.

With gating, FusionAuth blocks the unverified user instead. The hosted login pagesThe login, registration, password recovery, and multi-factor authentication pages that FusionAuth serves. A Theme controls the look of the pages. stop the user after login, and FusionAuth issues no JWT until the user verifies the email address. Gating applies after FusionAuth creates the user.

Pre-verification requires users to verify an email address before FusionAuth creates the user.

Configure the Tenant Email Server#

This guide uses the Admin UI. You can also configure everything with the API or with KickstartA file of API requests that FusionAuth runs on first startup to configure a new instance..

Log in to the Admin UI. Navigate to Tenants -> Your Tenant and select the Email tab. In the SMTP settings section, enter your SMTP server details.

The tenant Email tab with the SMTP settings.
The tenant Email tab with the SMTP settings.

Send a test email, and confirm that the email arrives. When the email doesn't arrive, see Troubleshooting Email.

Save the Tenant.

Turn On Email Verification Gating#

Navigate to Tenants -> Your Tenant and select the Identities tab. In the Identity verification settings section, configure the email settings:

  1. Turn on Verify identity.
  2. Set Verification template. The default Email verification template works for this guide.
  3. Set Verification strategy. ClickableLink sends an email with a link that verifies the email address. FormField sends a code that the user enters in FusionAuth. This guide uses ClickableLink.
  4. Set Unverified behavior to Gated.

The email settings look like the following:

The tenant Identities tab with gated email verification.
The tenant Identities tab with gated email verification.

Save the Tenant.

Customize the Email Verification Template#

When you want to change the verification email, navigate to Customizations -> Email Templates . Click on the Email Verification template.

Change the HTML and text templates, then save the template. You can also localize the email. For more information, see Email Templates.

The Email Verification email template.
The Email Verification email template.

Configure the Application#

Navigate to Applications and click on your Application.

On the Registration tab, go to the Self service registration section. Turn on self-service registration. Choose the fields that the registration form displays and requires.

Self-service registration is the simplest way to create a user with an unverified email address. Other ways of creating users also work with the gate.

The application Registration tab with self-service registration enabled.
The application Registration tab with self-service registration enabled.

On the OAuth tab, turn on the Authorization Code grant. Add a URL to Authorized redirect URLs. Any valid URL works for this guide. In production, the code at the redirect URL must exchange the authorization code for a token.

Save the Application. FusionAuth returns to the list of Applications.

Click on your Application to see the Application details.

The application details dialog with the login and registration URLs highlighted.
The application details dialog with the login and registration URLs highlighted.

Copy the Registration URL and the OAuth IdP login URL. The Registration URL looks like https://local.fusionauth.io/oauth2/register?client_id=85a03867-dccf-4882-adde-1a79aeec50df&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Foauth-redirect.

Test the Gate#

Register in a different browser or a private window, so your Admin UI session doesn't interfere with the registration:

  1. Open the Registration URL. Fill out the form with a valid email address. After registration, FusionAuth sends an email that asks you to verify the email address. The following screenshot shows the email in MailCatcher:

    The verification email in MailCatcher.
    The verification email in MailCatcher.

    The browser shows the email verification gate page:

    The email verification gate page for the clickable link strategy.
    The email verification gate page for the clickable link strategy.
  2. Open a different browser, not a new window of the same browser. Open the OAuth IdP login URL, and log in with the email address and password of the new user. FusionAuth shows the same email verification gate page.

  3. In the Admin UI, open the new user. A question mark next to the email address shows that the email address isn't verified.

    The user details page with an unverified email address.
    The user details page with an unverified email address.
  4. Click the link in the email. Log in again, and FusionAuth redirects to the redirect URL.

FusionAuth issues no JWT until the user verifies the email address, whichever API or hosted login page the user logs in with. Until then, the user sees the gate page at every login. When your application logs users in with the Login API, the response status code shows that the user hasn't verified the email address.

When Verification strategy is FormField, the gate page asks for the code from the email instead:

The email verification gate page for the form field strategy.
The email verification gate page for the form field strategy.

To make the gate page match your application, customize your theme. For more information, see Themes.

The User Object#

FusionAuth updates the email identity of the User during verification.

When email verification is off at user creation, verified is false and verifiedReason is Disabled:

User Object With Email Verification Turned Off Initially JSON
{
  "active": true,
  "birthDate": "1981-06-04",
  "connectorId": "e3306678-a53a-4964-9040-1c96f36dda72",
  "data": {
    "Company": "PiedPiper",
    "PreviousCompany": "Aviato",
    "user_type": "iconclast"
  },
  "email": "admin@fusionauth.io",
  "encryptionScheme": "salted-pbkdf2-hmac-sha256",
  "firstName": "Erlich",
  "id": "00000000-0000-0000-0000-000000000001",
  "identities": [
    {
      "primary": true,
      "type": "email",
      "value": "admin@fusionauth.io",
      "verified": false,
      "verifiedReason": "Disabled"
    }
  ],
  "insertInstant": 1630520102103,
  "lastLoginInstant": 1630639038934,
  "lastName": "Bachman",
  "lastUpdateInstant": 1630602397679,
  "passwordChangeRequired": false,
  "passwordLastUpdateInstant": 1630520102697,
  "tenantId": "30663132-6464-6665-3032-326466613934",
  "twoFactor": {},
  "usernameStatus": "ACTIVE",
  "verified": true
}

When email verification is on at user creation, verified is false and verifiedReason is Pending:

User Object With Email Verification Turned On Initially JSON
{
  "active": true,
  "birthDate": "1981-06-04",
  "connectorId": "e3306678-a53a-4964-9040-1c96f36dda72",
  "data": {
    "Company": "PiedPiper",
    "PreviousCompany": "Aviato",
    "user_type": "iconclast"
  },
  "email": "admin@fusionauth.io",
  "encryptionScheme": "salted-pbkdf2-hmac-sha256",
  "firstName": "Erlich",
  "id": "00000000-0000-0000-0000-000000000001",
  "identities": [
    {
      "primary": true,
      "type": "email",
      "value": "admin@fusionauth.io",
      "verified": false,
      "verifiedReason": "Pending"
    }
  ],
  "insertInstant": 1630520102103,
  "lastLoginInstant": 1630639038934,
  "lastName": "Bachman",
  "lastUpdateInstant": 1630602397679,
  "passwordChangeRequired": false,
  "passwordLastUpdateInstant": 1630520102697,
  "tenantId": "30663132-6464-6665-3032-326466613934",
  "twoFactor": {},
  "usernameStatus": "ACTIVE",
  "verified": false
}

After the user verifies the email address, verified is true and verifiedReason is Completed. Email verification also sets the User's top-level user.verified field to true. Phone verification doesn't change user.verified.

The Import Users API keeps the imported verification values, whatever the verification and gate settings.

Common Questions#

Do Existing Users Get Messages When I Enable a Gate?#

No. Enabling a gate sends no messages. Instead, an existing user with an unverified identity must verify the identity at their next login. An identity is unverified when the identity has verified: false and verifiedReason: "Pending". During login, the user clicks a link, and FusionAuth then sends the verification message.

When you use Elasticsearch for search, you can find the users that a gate will affect. Navigate to Users and search for verified: false. The search matches users with an unverified email address and users with an unverified registration.

Note

User search doesn't index the verification status of phone numbers. You can't search for users with an unverified phone number.

How Do I Mark an Imported User as Verified?#

To verify the email address or phone number of one user in the Admin UI:

  1. Navigate to Users and open the details page of the user.
  2. Click the down arrow next to Edit user , then select Verify identity .
  3. Select the identity and click Confirm .

The Admin UI can't mark a registration as verified. To verify a registration, or to verify many users at once, use the API:

  1. Get a verification Id from the Resend Verification API for an email address, or from the Resend Registration Verification API for a registration. Set sendVerifyEmail or sendVerifyRegistrationEmail to false, so FusionAuth returns the Id without sending an email.
  2. Send the verification Id to the Verify Email API or the Verify Registration API.

To skip this step in future imports, set users[x].verified and users[x].registrations[x].verified in the Import Users API.

What Happens When I Enable Both Email and Registration Verification?#

Email verification confirms that the user owns an email address, once per Tenant. Registration verification confirms that the user opted in to one Application. For example, nine Applications in a Tenant might require only email verification, while a tenth Application also requires registration verification.

When a new user signs up for the tenth Application, FusionAuth sends one email: the registration verification email. Completing registration verification also verifies the email address. When an existing user registers for the tenth Application, FusionAuth sends a registration verification email, even if the user already verified their email address.

When you turn off Allow implicit verification in the Tenant, registration verification doesn't verify the email address. Users then verify the registration and the email address separately. The setting is on the Identities tab of the Tenant. See Identity Verification Settings.

Troubleshooting Email Verification#

A user can't verify an email address or an Application registration. The link or code from the email has expired or returns an error.

Check the Email Template#

Check that the verification uses the right email template.

When users verify email addresses, set the Tenant's email verification template to Email Verification, not Registration Verification. The first screenshot shows the right template, and the second shows the wrong one:

The tenant email verification template set to the Email Verification template.
The tenant email verification template set to the Email Verification template.
The tenant email verification template set to the Registration Verification template.
The tenant email verification template set to the Registration Verification template.

When users verify Application registrations, set the Application's registration verification template to Registration Verification, not Email Verification. The first screenshot shows the right template, and the second shows the wrong one:

The application registration verification template set to the Registration Verification template.
The application registration verification template set to the Registration Verification template.
The application registration verification template set to the Email Verification template.
The application registration verification template set to the Email Verification template.

Check External Identifier Timeouts#

When links or codes expire before users use them, lengthen the external identifier durations. Navigate to Tenants -> Your Tenant -> Advanced . In the External identifier durations section, check Email verification, Phone verification, and Registration verification. FusionAuth sets a default for each duration.

The tenant Advanced tab with the verification durations highlighted.
The tenant Advanced tab with the verification durations highlighted.

Verification Emails Don't Arrive#

Send a test email from the Tenant's Email tab. When the test email doesn't arrive, see Troubleshooting Email.