Documentation Index
Fetch the complete documentation index at: https://auth0-feat-ionic-capacitor-quickstart-modernization.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Get Started
This quickstart demonstrates how to add Auth0 authentication to an Ionic Angular application with Capacitor. You’ll build a mobile-ready app with login, logout, and user profile features using the Auth0 Angular SDK and Capacitor’s native browser plugins.Install the Auth0 Angular SDK and Capacitor plugins
Install the Auth0 Angular SDK along with Capacitor’s Browser and App plugins:
@capacitor/browser- opens the Auth0 login page in the device’s system browser (SFSafariViewController on iOS, Chrome Custom Tabs on Android)@capacitor/app- handles deep link callbacks from Auth0 after authentication
Capacitor’s Browser plugin on iOS uses
SFSafariViewController, which on iOS 11+ does not share cookies with Safari. This means SSO will not work on those devices. If you need SSO, use a compatible plugin that uses ASWebAuthenticationSession.Setup your Auth0 App
Next up, you need to create a new app on your Auth0 tenant and add the environment variables to your project.You have three options to set up your Auth0 app: use the Quick Setup tool (recommended), run a CLI command, or configure manually via the Dashboard:
- Quick Setup (recommended)
- CLI
- Dashboard
Create a Native Auth0 App and copy the pre-filled environment file with the right configuration values.After creating your app, update the Allowed Callback URLs and Allowed Logout URLs in the Auth0 Dashboard Settings tab. Replace
YOUR_PACKAGE_ID with the appId from your capacitor.config.ts (default: io.ionic.starter):Allowed Callback URLs and Allowed Logout URLs:Configure the Auth0 module
With your environment file in place from the previous step, configure the Auth0 module in your app:The
src/main.ts
provideAuth0 configuration includes:useRefreshTokens: true— required for mobile. Capacitor apps cannot use iframe-based silent authentication, so refresh tokens are used to renew sessions.useRefreshTokensFallback: false— required for mobile. Prevents the SDK from falling back to iframe-based silent auth, which is unavailable in native apps.authorizationParams.redirect_uri— uses your app’s custom URL scheme to redirect back after authentication.
Create Login, Logout and Profile components
Create the component filesAdd the following code to each component:Now update the App Component to handle Auth0 callbacks, and the home page to use your components:
- App Component
- Home Page
Replace the contents of
src/app/app.component.ts:src/app/app.component.ts
The
appUrlOpen event callback in the App Component is wrapped in this.ngZone.run(). This is required because Capacitor plugin callbacks execute outside Angular’s zone, and without it Angular won’t detect the auth state changes after login. See Using Angular with Capacitor for details.CheckpointYou should now have a fully functional Auth0 login page running on your localhost
Advanced Usage
Using Traditional NgModule Approach
Using Traditional NgModule Approach
If you created your project with
--type=angular (instead of --type=angular-standalone) or prefer using NgModules, configure the SDK with AuthModule.forRoot:src/app/app.module.ts
When using NgModules, inject
AuthService via the constructor (constructor(public auth: AuthService)) instead of inject(). Use *ngIf="auth.user$ | async as user" in templates instead of @if control flow syntax. Components should be declared in the module rather than marked as standalone: true.Custom URL Scheme Setup
Custom URL Scheme Setup
To test authentication on a real device, register your custom URL scheme for each platform.Replace Replace Or for Android:
iOS
Register your custom URL scheme inios/App/App/Info.plist:YOUR_PACKAGE_ID with your appId from capacitor.config.ts. To learn more, read Defining a Custom URL Scheme.Android
Add an intent filter toandroid/app/src/main/AndroidManifest.xml inside the <activity> tag:YOUR_PACKAGE_ID with your appId from capacitor.config.ts. To learn more, read Create Deep Links to App Content.Build and run on device
Protecting Routes with AuthGuard
Protecting Routes with AuthGuard
Use the functional guard to protect routes that require authentication:When unauthenticated users navigate to a protected route,
src/app/app.routes.ts
authGuardFn automatically redirects them to the Auth0 login page.Calling Protected APIs
Calling Protected APIs
Configure the HTTP interceptor to automatically attach access tokens to API calls:Then make API calls using Angular’s
src/main.ts
HttpClient — the interceptor automatically attaches the Bearer token:src/app/api.service.ts
Common Issues & Solutions
Common Issues & Solutions
Callback URL mismatch error
Solution: Verify the callback URL in your Auth0 Dashboard matches exactly with the URL constructed in your app. EnsureYOUR_PACKAGE_ID matches the appId field in your capacitor.config.ts.Screen does not update after login
Solution: Ensure theappUrlOpen event callback is wrapped in this.ngZone.run(). Without this, Angular won’t detect the state changes from handleRedirectCallback. See Using Angular with Capacitor.”PKCE not allowed” error
Fix:- Go to Auth0 Dashboard > Applications > Your Application
- Change the Application Type to Native
- Set Token Endpoint Authentication Method to
None - Save changes and try again
SSO not working on iOS
Capacitor’s Browser plugin usesSFSafariViewController, which does not share cookies with Safari on iOS 11+. If you need SSO, use a compatible plugin that uses ASWebAuthenticationSession.Login works but user stays unauthenticated after app restart
EnablecacheLocation: 'localstorage' in the provideAuth0 configuration to persist tokens across app restarts. Be aware of the security implications and Capacitor storage limitations.Observable never executes
AllAuthService methods return cold Observables. You must call .subscribe() for them to execute. If loginWithRedirect() or logout() appears to do nothing, check that .subscribe() is chained at the end.Next Steps
Check out the following resources to learn more:- Sample Application — A complete Ionic Angular sample app with Auth0 integration
- Auth0 Angular SDK Documentation — Full SDK reference and examples
- Auth0 Dashboard — Configure and manage your Auth0 tenant and applications
- Auth0 Marketplace — Discover integrations you can enable to extend Auth0’s functionality