React Native

View on Github

React Native

Gravatar for
By Martin Walsh

This tutorial demonstrates how to add user login to a React Native application using Auth0. We recommend you to Log in to follow this quickstart with examples configured for your account.

I want to explore a sample app

2 minutes

Get a sample configured with your account settings or check it out on Github.

View on Github
System requirements: React Native 0.59.10 | NodeJS 10.16

New to Auth? Learn How Auth0 works, how it integrates with Native Applications and which protocol it uses.

Configure Auth0

Get Your Application Keys

When you signed up for Auth0, a new application was created for you, or you could have created a new one.

You will need some details about that application to communicate with Auth0. You can get these details from the Application Settings section in the Auth0 dashboard.

You need the following information:

  • Domain
  • Client ID

If you download the sample from the top of this page these details are filled out for you.

If you have more than one application in your account, the sample comes with the values for your Default App.

App Dashboard

Configure Callback URLs

A callback URL is a URL in your application where Auth0 redirects the user after they have authenticated.

The callback URL for your app must be whitelisted in the Allowed Callback URLs field in your Application Settings. If this field is not set, users will be unable to log in to the application and will get an error.

iOS Callback

Remember to replace PRODUCT_BUNDLE_IDENTIFIER with your actual application's bundle identifier name.

Inside the ios folder open the Info.plist and locate the value for CFBundleIdentifier. In the sample project the value is:

Android Callback

Remember to replace YOUR_APP_PACKAGE_NAME with your actual application's package name.

You can find this at the top of your AndroidManifest.xml file located in the android/app/src/main/ folder. In the sample project the value is:

Configure Logout URLs

A logout URL is a URL in your application that Auth0 can return to after the user has been logged out of the authorization server. This is specified in the returnTo query parameter.

The logout URL for your app must be whitelisted in the Allowed Logout URLs field in your Application Settings. If this field is not set, users will be unable to log out from the application and will get an error.

If you are following along with the sample project you downloaded from the top of this page, the logout URL you need to whitelist in the Allowed Logout URLs field is the same as the callback URL.

Install Dependencies

How to install the React Native Auth0 module.

Please refer to the official documentation for additional details on React Native.



For further reference on yarn, check their official documentation.

To add the functionality of the React Native Auth0 module to your project you need to link it.

For further reference on linking libraries, check the official documentation.

The first step in adding authentication to your application is to provide a way for your users to log in. The fastest, most secure, and most feature-rich way to do this with Auth0 is to use the hosted login page.

Login Page

Integrate Auth0 in your Application

Configure Android

In the file android/app/src/main/AndroidManifest.xml you must make sure the MainActivity of the app has a launchMode value of singleTask and that it has the following intent filter:

So your MainActivity should look like this:

Configure iOS

In the file ios/<YOUR PROJECT>/AppDelegate.m add the following:

Next you will need to add a URLScheme using your App's bundle identifier.

Inside the ios folder open the Info.plist and locate the value for CFBundleIdentifier

and then register a URL type entry using the value of CFBundleIdentifier as the value for the CFBundleURLSchemes

The value org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) is the default for apps created with React Native CLI, you may have a different value.

Add Authentication with Auth0

Universal login is the easiest way to set up authentication in your application. We recommend using it for the best experience, best security and the fullest array of features.

You can also embed login functionality directly in your application. If you use this method, some features, such as single sign-on, will not be accessible. To learn how to embed functionality using a custom login form in your application, follow the Custom Login Form Sample. Make sure you read the Browser-Based vs. Native Login Flows on Mobile Devices article to learn how to choose between the two types of login flows.

First, import the Auth0 module and create a new Auth0 instance.

Then present the hosted login screen, like this:

Upon successful authentication the user's credentials will be returned, containing an access_token, an id_token and an expires_in value.

For more information on the accessToken, refer to Access Token.

Log the User Out

To log the user out, redirect them to the Auth0 log out endpoint by calling clearSession. This will remove their session from the authorization server. After this happens, remove the Access Token from the state.

Use Auth0 for FREE