Using Passwordless Authentication with a Magic Link via email on SPA

Instead of sending the user a one time code, you can configure Auth0 to send a magic link:

Auth0 will send an email containing a clickable button or link:

After clicking the button, the user will be automatically signed-in to your application:


Configure an email provider

By default, Auth0 sends the email from its own SMTP provider. Auth0's built-in email infrastructure should be used for testing level emails only. You can configure your own email provider to better monitor and troubleshoot the email service as well as be able to fully customize the emails.

You will need to use your own email provider to be able to modify the From, Subject and Body of Passwordless emails.

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

Configure Callback URL

For security purposes, you must add your page's URL to the list of Allowed callback URLs in your application's Settings section of the Dashboard.


Use Lock (the Auth0 UI widget)

Lock with Passwordless Mode 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 (version 11.2.0 or later), you must initialize it with your Client Id and domain. You can find this information in the Dashboard on your application settings page.

Then you can trigger the passwordless authentication using a magic link with the following code:

<script src=""></script>

<script type="text/javascript">
   var lock = new Auth0LockPasswordless('YOUR_CLIENT_ID', 'YOUR_AUTH0_DOMAIN', {
    passwordlessMethod: "link",              // Sets Lock to use magic link
    auth: {
      redirectUrl: 'https://YOUR_APP/callback',
      responseType: 'token id_token'
  lock.on('authenticated', function(authResult) {
     localStorage.setItem('id_token', authResult.idToken);
     localStorage.setItem('access_token', authResult.accessToken);
  function login(){;

<a href="javascript:login()">Login</a>

If you use custom domains, replace YOUR_AUTH0_DOMAIN with your custom domain.

The user will receive an email with the magic link. Once the user clicks on this link, Auth0 will handle the authentication and redirect back to the application.

You can follow any of the Single Page App Quickstarts to see more about using Auth0.js in a SPA.

Use your own UI

Sample Project

Download a sample project specific to this tutorial configured with your Auth0 API Keys.

You can perform passwordless authentication with a magic link in your single-page application using your own UI with the Auth0 JavaScript client library.

Construct a new instance of the Auth0 client as follows:

<script src=""></script>
<script type="text/javascript">
  var webAuth = new auth0.WebAuth({
    domain:       'YOUR_AUTH0_DOMAIN',
    clientID:     'YOUR_CLIENT_ID',
    redirectUri: 'https://YOUR_APP/callback'

You must provide a way for the user to enter an email to which the magic link will be sent. Then you can begin the passwordless authentication as follows (assuming the name of your form input as

function sendEmail(){
  var email = $('').val();

    connection: 'email',
    send: 'link',
    email: email
  }, function (err,res) {
    if (err) {
      // Handle error
    // Hide the input and show a "Check your email for your login link!" screen

This will send an email containing the magic link. After clicking the link, the user will be automatically signed in and redirected to the redirectUri which can be specified in the Auth0 constructor, where you will need to parse the token with webAuth.parseHash:

//parse hash on page load
  webAuth.parseHash({hash: window.location.hash}, function(err, authResult) {
    if (err) {
      return console.log(err);

    webAuth.client.userInfo(authResult.accessToken, function(err, user) {
      // Now you have the user's information

With magic link transactions, both the initial request and the response to the request must take place in the same browser. This is particularly relevant for iOS users, who cannot change their default web browswer. For example, the user makes the request using Chrome, but iOS opens the magic link received via email using Safari. If this happens, the transaction fails.

Check out the Auth0.js SDK reference documentation for more information.