Loading...
Loading...
Use when adding Auth0 login, logout, or deep linking to an Ionic React app with Capacitor. Integrates @auth0/auth0-react with Capacitor Browser and App plugins for native iOS/Android.
npx skill4agent add auth0/agent-skills auth0-ionic-react@auth0/auth0-react@capacitor/browser@capacitor/appnpm install -g @ionic/clibrew install auth0/auth0-cli/auth0| Use Case | Recommended Skill |
|---|---|
| React SPA (no Capacitor/Ionic) | |
| React Native (bare CLI) | |
| Expo (React Native) | |
| Ionic + Angular + Capacitor | |
| Ionic + Vue + Capacitor | |
| Next.js (server-side) | |
| iOS native (Swift) | |
| Android native (Kotlin) | |
npm install @auth0/auth0-react @capacitor/browser @capacitor/app
npx cap syncAuth0Providersrc/main.tsximport React from 'react';
import { createRoot } from 'react-dom/client';
import { Auth0Provider } from '@auth0/auth0-react';
import App from './App';
const domain = import.meta.env.VITE_AUTH0_DOMAIN;
const clientId = import.meta.env.VITE_AUTH0_CLIENT_ID;
const packageId = import.meta.env.VITE_AUTH0_PACKAGE_ID; // e.g., com.example.myapp
const redirectUri = `${packageId}://${domain}/capacitor/${packageId}/callback`;
createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<Auth0Provider
domain={domain}
clientId={clientId}
useRefreshTokens={true}
useRefreshTokensFallback={false}
authorizationParams={{
redirect_uri: redirectUri
}}
>
<App />
</Auth0Provider>
</React.StrictMode>
);import { useAuth0 } from '@auth0/auth0-react';
import { Browser } from '@capacitor/browser';
const { loginWithRedirect } = useAuth0();
const login = async () => {
await loginWithRedirect({
async openUrl(url) {
await Browser.open({ url, windowName: "_self" });
}
});
};import { useEffect } from 'react';
import { App as CapApp } from '@capacitor/app';
import { Browser } from '@capacitor/browser';
import { useAuth0 } from '@auth0/auth0-react';
const { handleRedirectCallback } = useAuth0();
useEffect(() => {
const listener = CapApp.addListener('appUrlOpen', async ({ url }) => {
if (url.includes('state') && (url.includes('code') || url.includes('error'))) {
await handleRedirectCallback(url);
}
await Browser.close();
});
return () => {
listener.then(l => l.remove());
};
}, [handleRedirectCallback]);const doLogout = async () => {
await logout({
logoutParams: {
returnTo: `${packageId}://${domain}/capacitor/${packageId}/callback`
},
async openUrl(url) {
await Browser.open({ url, windowName: "_self" });
}
});
};Agent instruction: After integration, verify the build:bashionic build npx cap syncFor iOS:then build in Xcode. For Android:npx cap open iosthen build in Android Studio. If the build fails, iterate up to 5-6 times to fix issues. If still failing, usenpx cap open androidto request help.AskUserQuestion
| Mistake | Fix |
|---|---|
| App type not set to Native in Auth0 Dashboard | Change application type to "Native" in Dashboard settings |
| Missing or incorrect callback URL format | Use |
| Not enabling refresh tokens | Set |
Missing | Install both: |
| Not handling deep link callback | Add |
Forgetting | Always run |
Using | Use the custom URL scheme ( |
| Missing Allowed Origins in Dashboard | Add |
| localStorage treated as persistent on mobile | Use refresh tokens ( |
| iOS SSO not working | SFSafariViewController doesn't share cookies with Safari on iOS 11+; this is expected |
| Not testing on physical device | Always test auth flows on a physical device; simulators may not handle deep links correctly |
loginWithRedirect(){packageId}://{domain}/capacitor/{packageId}/callback@capacitor/apphandleRedirectCallback(url)https://{domain}/android/{packageId}/callbackhttps://{domain}/ios/{bundleId}/callback| API | Description |
|---|---|
| Context provider — wraps app root with Auth0 config |
| Hook — returns |
| Login via Universal Login — use |
| Logout — use |
| Process Auth0 callback URL from deep link |
| Get access token (uses refresh tokens on mobile) |
| HOC to protect routes |
| Capacitor — opens URL in system browser (SFSafariViewController / Chrome Custom Tabs) |
| Capacitor — listens for deep link events |
| Capacitor — closes the in-app browser after callback |