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 Vue application running on iOS and Android with Capacitor. You’ll build a secure mobile app with login, logout, and user profile features using the Auth0 Vue SDK and Capacitor’s native browser plugins.Install the Auth0 Vue SDK and Capacitor plugins
@capacitor/browser opens the Auth0 Universal Login page in the device’s system browser (SFSafariViewController on iOS, Chrome Custom Tabs on Android) for secure authentication.@capacitor/app listens for deep link events so your app can handle the OAuth callback when Auth0 redirects back after login.Setup your Auth0 App
Next up, you need to create a new app on your Auth0 tenant. Ionic Capacitor apps use the Native application type with custom URL scheme callbacks.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 an Auth0 Native application and get your credentials.After creating your app, note the Domain and Client ID values for the next step.
You’ll also need to configure callback and logout URLs in the Dashboard. See the URL configuration below.
Configure the Auth0 Plugin
src/main.ts
useRefreshTokens: true— Mobile browsers block third-party cookies, so iframe-based silent auth doesn’t work. Refresh tokens call the/oauth/tokenendpoint directly.useRefreshTokensFallback: false— Prevents the SDK from attempting the iframe-based fallback, which is unavailable on mobile.router.isReady().then(...)— Ensures Vue Router is fully initialized before the SDK processes the OAuth callback, preventing race conditions.
Create Authentication Components
Create component filesAdd the following code to the new components, and update the existing
App.vue and HomePage.vueRun your app
If port 8100 is in use, run:
ionic serve --port 8101 and update your Auth0 app’s callback URLs accordingly.To test on a device or emulator, run ionic cap run ios or ionic cap run android. Make sure you’ve registered the custom URL scheme for your platform first.CheckpointYou should now have a fully functional Auth0 login experience in your Ionic Vue application with login, logout, and user profile information.
Advanced Usage
Custom URL Scheme Setup
Custom URL Scheme Setup
Register your app’s custom URL scheme so the OS can route the OAuth callback back to your app after authentication.Replace To learn more, read Create Deep Links to App Content.
iOS
Register your custom URL scheme in yourios/App/App/Info.plist:YOUR_PACKAGE_ID with the appId from your capacitor.config.ts. To learn more, read Defining a Custom URL Scheme.Android
Add an intent filter to yourandroid/app/src/main/AndroidManifest.xml inside the main <activity> tag:Protecting Routes with Vue Router
Protecting Routes with Vue Router
Use the built-in The
authGuard from the Auth0 Vue SDK to protect routes that require authentication:src/router/index.ts
authGuard automatically redirects unauthenticated users to the Auth0 Universal Login page. After logging in, they are returned to the originally requested route.Calling Protected APIs
Calling Protected APIs
Configure the Then use
audience parameter in your createAuth0 configuration to request access tokens for your API:src/main.ts
getAccessTokenSilently in your components to retrieve tokens and make authenticated API calls:src/components/ApiCall.vue
Using defineComponent Pattern
Using defineComponent Pattern
If you prefer the explicit The
defineComponent pattern over <script setup>, here’s how the LoginButton component looks using that approach:src/components/LoginButton.vue
defineComponent pattern requires explicitly registering child components and returning values from the setup() function. Both patterns are fully supported by the Auth0 Vue SDK.Common Issues & Solutions
Common Issues & Solutions
Callback URL mismatch error
Solution: Verify that the callback URL in your Auth0 Dashboard matches exactly with the URL constructed in your application. EnsureYOUR_PACKAGE_ID matches the appId field in your capacitor.config.ts.”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 createAuth0 configuration to persist tokens across app restarts. Be aware of the security implications. The SDK also supports custom cache implementations for more secure storage.Browser doesn’t close after login
Ensure you are callingBrowser.close() inside the appUrlOpen event listener in your App.vue component. On Android, Browser.close() is a no-op, so the browser closes automatically.Login page opens in the device’s default browser app
If the login page opens in Safari or Chrome instead of an in-app browser overlay, make sure you’re passing theopenUrl callback to loginWithRedirect and logout. Without it, the SDK defaults to window.location.href, which navigates the entire app away.