Get Started
1
Create a new React Native project
Create a new React Native project for this quickstart.In your terminal:Configure your project with:
- Name:
Auth0ReactNativeSample - Package name:
com.auth0.samples.reactnative
2
Install the Auth0 SDK
Add the Auth0 React Native SDK to your project.For iOS, install the native dependencies:
3
Configure your Auth0 Application
Create and configure an Auth0 application to work with your React Native app.Allowed Logout URLs:Replace
- Head to the Auth0 Dashboard
- Click on Applications > Applications > Create Application
- In the popup, enter a name for your app (e.g.,
Auth0 React Native Sample), selectNativeas the app type and click Create - Switch to the Settings tab on the Application Details page
- Note your Domain and Client ID values
{yourDomain} with your actual Auth0 domain (e.g., dev-abc123.us.auth0.com).Allowed Callback URLs are a critical security measure to ensure users are safely returned to your application after authentication. Without a matching URL, the login process will fail, and users will be blocked by an Auth0 error page instead of accessing your app.Allowed Logout URLs are essential for providing a seamless user experience upon signing out. Without a matching URL, users will not be redirected back to your application after logout and will instead be left on a generic Auth0 page.The URL scheme includes
.auth0 after your bundle identifier to ensure the callback is routed to your specific app. For this quickstart, the bundle identifier is org.reactjs.native.example.auth0reactnativesample.4
Configure Native Platforms
Configure both iOS and Android to handle the authentication callback.Android Configuration:Open Replace Open
android/app/build.gradle and add the manifest placeholders inside defaultConfig:android/app/build.gradle
{yourDomain} with your Auth0 domain (e.g., dev-abc123.us.auth0.com).iOS Configuration:- AppDelegate.mm (Objective-C)
- AppDelegate.swift (Swift)
Open
ios/Auth0ReactNativeSample/AppDelegate.mm and add the URL handling method:ios/Auth0ReactNativeSample/AppDelegate.mm
ios/Auth0ReactNativeSample/Info.plist and add the URL scheme. Add this before the closing </dict> tag:ios/Auth0ReactNativeSample/Info.plist
The URL scheme uses your bundle identifier with
.auth0 appended. This ensures the callback is routed to your specific app after authentication completes in the browser.5
Setup App Component
Setup your main app component based on your chosen implementation approach.
- Hooks-based (with Provider)
- Class-based (without Provider)
Replace the contents of Replace
App.tsx and wrap your application with the Auth0Provider component:App.tsx
{yourDomain} with your Auth0 domain and {yourClientId} with your Client ID from the Auth0 Dashboard.6
Implement Login and Logout
Create a screen component that handles login and logout. You can choose between a hooks-based approach (recommended) or a class-based approach.
- Hooks-based (Recommended)
- Class-based
Create
src/MainScreen.tsx using the useAuth0 hook:src/MainScreen.tsx
The
authorize() method (hooks) or auth0.webAuth.authorize() (class) opens Auth0’s Universal Login in a secure browser (ASWebAuthenticationSession on iOS, Chrome Custom Tabs on Android). The clearSession() method logs the user out and clears both the browser session and stored credentials.7
Run your app
Build and run your React Native application on a device or emulator.For iOS (requires macOS):For Android:Expected flow:
- App launches showing “Log In” button
- Tap Log In → Browser opens with Auth0 Universal Login
- Complete login (sign up or sign in)
- Browser closes → Returns to app automatically
- User profile displays with name, email, and avatar
CheckpointYou should now have a fully functional Auth0 login experience running on your device or emulator. The app uses secure browser authentication and automatically manages credentials.
Troubleshooting & Advanced
Common Issues & Solutions
Common Issues & Solutions
”Callback URL mismatch” error
Solution:- Verify the exact URL (including
.auth0suffix) is in Allowed Callback URLs in your Auth0 Dashboard - Ensure both iOS and Android URLs are added
- Check that
{yourDomain}is replaced with your actual Auth0 domain
App doesn’t return after login (iOS)
Fix:- Check
Info.plisthas theCFBundleURLSchemesentry with$(PRODUCT_BUNDLE_IDENTIFIER).auth0 - Verify
AppDelegate.mmincludes the URL handling method - Ensure the URL scheme matches your bundle identifier
Android build fails
Fix:- Add
auth0Domainandauth0Schememanifest placeholders tobuild.gradle - Sync project with Gradle files
- Clean build:
./gradlew clean
”PKCE not allowed” error
Fix:- Go to Auth0 Dashboard → Applications → Your Application
- Change application type to Native
- Save changes and try again
Pod install fails (iOS)
Fix:- Update CocoaPods:
sudo gem install cocoapods - Update pod repo:
pod install --repo-update - If issues persist, delete
Podfile.lockandios/Podsfolder, then runpod installagain
User cancelled error
Handle gracefully in your login function:iOS Alert Dialog
On iOS, users see a permission dialog: “App Name” Wants to Use “auth0.com” to Sign In. This is expected behavior fromASWebAuthenticationSession. Users must tap Continue to proceed.To customize this behavior, you can use ephemeral sessions (disables SSO):Retrieving Access Tokens
Retrieving Access Tokens
Use the
getCredentials() method to retrieve tokens for API calls:Check Authentication Status on App Launch
Check Authentication Status on App Launch
Use
hasValidCredentials() to check if the user is already logged in:Production Deployment
Production Deployment
Before deploying to production
Use HTTPS callback URLs for enhanced security:- Settings → Advanced Settings → Device Settings
- Add your app’s SHA-256 fingerprint
- Add Associated Domains capability in Xcode
- Add
webcredentials:{yourDomain}to Associated Domains
localAuthenticationOptions in Auth0ProviderReview security settings in Auth0 Dashboard:- Enable OIDC Conformant in Advanced Settings
- Configure Token Expiration appropriately
- Set up Brute Force Protection
- Test on multiple devices and OS versions
- Implement proper error handling for network failures