Authenticate users with a one-time code via e-mail on SPA

This document uses an older version of auth0.js. We recommend you to upgrade to the latest version.


1. Optional: Configure an email provider

By default, Auth0 sends the email from its own messaging provider. Optionally, you can configure your own email provider to better monitor and troubleshoot the email service.

2. Configure the connection

In the Dashboard, on the Email page, under Connections > Passwordless, you can configure the contents and behavior of the email.

Multi-Language Support

The Message area supports usage of multiple languages.

By making a call to the /passwordless/start authentication endpoint, you can set the value of an 'x-request-language' header to the language of your choice. If the value of this header is not set, the language will be extracted from the value in the 'accept-language' header that is automatically set by the browser.

The Message area accepts Liquid syntax. You can use this syntax, combined with exposed parameter values, to programmatically construct elements of the message. For example, you can reference the request_language parameter to change the language of the message:

{% if request_language contains 'dutch' %}
   Hier is uw verificatie code: {{ code }}
{% endif %}

{% if request_language contains 'fr-FR' %}
   Ceci est votre code: {{ code }}
{% endif %}

The following parameters are available when defining the template:

Exposed Parameter Description
code the password to use
link the magic link the name of the application name where the user is signing up
request_language the requested language for the message content
operation equals change_email when the template is triggered by an update to a user's email via the API, otherwise null

4. Configure CORS

For security purposes, you must add your app's origin URL to the list of Allowed Origins (CORS) in your app's Settings Section of the Dashboard, unless this origin URL has been already added to the Allowed callback URLs list.


Use Auth0 UI widget (Lock)

Auth0 Lock Passwordless is a professional-looking dialog that allows users to log in after receiving a one-time password via email or text message.

After installing Lock Passwordless, you must initialize it with your Client Id and domain. You can find this information on your application settings page.

Then you can trigger the login with the following code:

<script src=""></script>
<script type="text/javascript">
  function login(){
    // Initialize Passwordless Lock instance
    var lock = new Auth0LockPasswordless('YOUR_CLIENT_ID', 'YOUR_AUTH0_DOMAIN');
    // Open the lock in Email Code mode with the ability to handle
    // the authentication in page
    lock.emailcode( function (err, profile, id_token, state) {
      if (!err) {
        // Save the JWT token.
        localStorage.setItem('userToken', id_token);
        //use profile
<a href="javascript:login()">Login</a>

First, this will open a dialog that asks the user for their email address:

Then Auth0 will send an email to the user containing the one-time code:

Lock will ask for the code that has been emailed to the provided address. The code can then be used as a one-time password to log in.

Once the user enters the code received by email, Lock will authenticate them and call the callback function where the id_token and profile will be available.

Use your own UI

You can perform passwordless authentication in your SPA with your own custom UI using the Auth0 JavaScript client library.

Construct a new instance of the Auth0 client as follows:

<script src=""></script>
<script type="text/javascript">
  'use strict';
  const auth0 = new Auth0({
    clientID: 'YOUR_CLIENT_ID',
    domain: 'YOUR_AUTH0_DOMAIN'

You must provide a way for the user to enter the email to which the one-time code will be sent. Then you can begin the passwordless authentication with the following code:

function sendEmail(){
  var email = $('').val();
  auth0.requestEmailCode({ email: email }, function(err) {
    if (err) {
      alert('error sending e-mail: ' + err.error_description);
    // the request was successful and you should
    // receive the code to the specified email

This will send an email containing the one-time code. The user must now enter the code into your custom UI. Then you can continue with the login as follows:

function login(){
  var email = $('').val();
  var code = $('input.code').val();

  //submit the passcode to complete authentication
  auth0.verifyEmailCode({ email: email, code: code }, function(err, profile, id_token, access_token) {
      if (err) {
        alert('Couldn\'t login ' + err.message);
      } else {

        //save id_token to local storage
        localStorage.setItem('userToken', id_token);

        //use profile
        alert('Welcome '+;
Was this article helpful?