Loading...
Loading...
Use when adding Auth0 login, logout, or deep linking to an Ionic Vue app with Capacitor. Integrates @auth0/auth0-vue with Capacitor Browser and App plugins for native iOS/Android.
npx skill4agent add auth0/agent-skills auth0-ionic-vue@auth0/auth0-vue@capacitor/browser@capacitor/appnpm install -g @ionic/clibrew install auth0/auth0-cli/auth0| Use Case | Recommended Skill |
|---|---|
| Vue SPA (no Capacitor/Ionic) | |
| React SPA (no Capacitor/Ionic) | |
| React Native (bare CLI) | |
| Expo (React Native) | |
| Ionic + React + Capacitor | |
| Ionic + Angular + Capacitor | |
| Next.js (server-side) | |
| Nuxt (server-side) | |
| iOS native (Swift) | |
| Android native (Kotlin) | |
npm install @auth0/auth0-vue @capacitor/browser @capacitor/app
npx cap syncAgent instruction: If Step 1 already wroteand updated.env, verify the configuration looks correct and skip to Step 4. Only use the template below if configuring manually.src/main.ts
src/main.ts.envimport.meta.envimport { createApp } from 'vue';
import { createAuth0 } from '@auth0/auth0-vue';
import { IonicVue } from '@ionic/vue';
import App from './App.vue';
import router from './router';
// Agent: read appId from capacitor.config.ts and replace this value
const packageId = "YOUR_PACKAGE_ID";
const app = createApp(App);
app.use(IonicVue);
app.use(router);
app.use(
createAuth0({
domain: import.meta.env.VITE_AUTH0_DOMAIN,
clientId: import.meta.env.VITE_AUTH0_CLIENT_ID,
useRefreshTokens: true,
useRefreshTokensFallback: false,
authorizationParams: {
redirect_uri: `${packageId}://${import.meta.env.VITE_AUTH0_DOMAIN}/capacitor/${packageId}/callback`
}
})
);
router.isReady().then(() => {
app.mount('#app');
});<script setup lang="ts">
import { useAuth0 } from '@auth0/auth0-vue';
import { Browser } from '@capacitor/browser';
import { IonButton } from '@ionic/vue';
const { loginWithRedirect } = useAuth0();
const login = async () => {
await loginWithRedirect({
async openUrl(url: string) {
await Browser.open({ url, windowName: "_self" });
}
});
};
</script>
<template>
<ion-button @click="login">Log in</ion-button>
</template><script setup lang="ts">
import { onMounted, onUnmounted } from 'vue';
import { useAuth0 } from '@auth0/auth0-vue';
import { App as CapApp } from '@capacitor/app';
import { Browser } from '@capacitor/browser';
import { IonApp, IonRouterOutlet } from '@ionic/vue';
const { handleRedirectCallback } = useAuth0();
let urlOpenListener: any;
onMounted(async () => {
urlOpenListener = await CapApp.addListener('appUrlOpen', async ({ url }) => {
if (url.includes('state') && (url.includes('code') || url.includes('error'))) {
await handleRedirectCallback(url);
}
await Browser.close();
});
});
onUnmounted(() => {
urlOpenListener?.remove();
});
</script>
<template>
<ion-app>
<ion-router-outlet />
</ion-app>
</template><script setup lang="ts">
import { useAuth0 } from '@auth0/auth0-vue';
import { Browser } from '@capacitor/browser';
import { IonButton } from '@ionic/vue';
const domain = import.meta.env.VITE_AUTH0_DOMAIN;
// Agent: read appId from capacitor.config.ts and replace this value
const packageId = "YOUR_PACKAGE_ID";
const logoutUri = `${packageId}://${domain}/capacitor/${packageId}/callback`;
const { logout } = useAuth0();
const doLogout = async () => {
await logout({
logoutParams: {
returnTo: logoutUri
},
async openUrl(url: string) {
await Browser.open({ url, windowName: "_self" });
}
});
};
</script>
<template>
<ion-button @click="doLogout">Log out</ion-button>
</template>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 |
Not calling | Register Auth0 plugin before calling |
Accessing | |
| localStorage treated as persistent on mobile | Use refresh tokens ( |
loginWithRedirect(){packageId}://{domain}/capacitor/{packageId}/callback@capacitor/apphandleRedirectCallback(url)https://{domain}/android/{packageId}/callbackhttps://{domain}/ios/{bundleId}/callback| API | Description |
|---|---|
| Vue plugin factory — registers Auth0 with |
| Composable — returns |
| Login via Universal Login — use |
| Logout — use |
| Process Auth0 callback URL from deep link |
| Get access token (uses refresh tokens on mobile) |
| Vue Router navigation guard factory for protected 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 |