@asgardeo/vue QuickstartThis guide will help you quickly integrate Asgardeo authentication into your Vue.js application.
Quickstart tab
https://api.asgardeo.io/t/<your-organization-name>)Protocol tab
https://localhost:5173If you don’t have a Vue application set up yet, you can create one using create-vue:
# Using npm
npm create vue@latest vue-sample
# Using pnpm
pnpm create vue@latest vue-sample
# Using yarn
yarn create vue vue-sample
When prompted, enable TypeScript for a better development experience.
Alternatively, using Vite:
# Using npm
npm create vite@latest vue-sample --template vue-ts
# Using pnpm
pnpm create vite@latest vue-sample --template vue-ts
# Using yarn
yarn create vite vue-sample --template vue-ts
Navigate to your project:
cd vue-sample
Install the Asgardeo Vue SDK in your project:
# Using npm
npm install @asgardeo/vue
# Using pnpm
pnpm add @asgardeo/vue
# Using yarn
yarn add @asgardeo/vue
Register the Asgardeo plugin and wrap your application with the AsgardeoProvider in your main entry file (src/main.ts):
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import { AsgardeoPlugin, AsgardeoProvider } from '@asgardeo/vue'
const app = createApp(App)
app.use(AsgardeoPlugin, {
baseUrl: '<your-organization-base-url>',
clientId: '<your-app-client-id>',
})
app.mount('#app')
Replace:
<your-organization-base-url> with the Base URL you noted in Step 1 (e.g., https://api.asgardeo.io/t/<your-organization-name>)<your-app-client-id> with the Client ID from Step 1Then wrap your app component with the AsgardeoProvider in src/App.vue:
<script setup>
import { AsgardeoProvider } from '@asgardeo/vue'
</script>
<template>
<AsgardeoProvider>
<!-- Your application content goes here -->
</AsgardeoProvider>
</template>
Update your src/App.vue to include sign-in and sign-out functionality:
<script setup lang="ts">
import { SignedIn, SignedOut, SignInButton, SignOutButton } from '@asgardeo/vue'
</script>
<template>
<div>
<SignedIn>
<SignOutButton />
</SignedIn>
<SignedOut>
<SignInButton />
</SignedOut>
</div>
</template>
<style scoped>
/* Your custom styles */
</style>
You can also display user information by using the User component and the useUser composable:
<script setup lang="ts">
import { SignedIn, SignedOut, SignInButton, SignOutButton, User } from '@asgardeo/vue'
import { useUser } from '@asgardeo/vue'
const { user, isLoading } = useUser()
</script>
<template>
<div>
<SignedIn>
<div v-if="!isLoading" class="user-info">
<h1>Welcome, </h1>
<p>Email: </p>
</div>
<div v-else>
Loading user information...
</div>
<SignOutButton />
</SignedIn>
<SignedOut>
<SignInButton />
</SignedOut>
</div>
</template>
<style scoped>
.user-info {
padding: 1rem;
border: 1px solid #e0e0e0;
border-radius: 4px;
margin-bottom: 1rem;
}
h1 {
margin: 0 0 0.5rem 0;
font-size: 1.5rem;
}
p {
margin: 0;
color: #666;
}
</style>
Alternatively, you can use the User component with a render function:
<script setup lang="ts">
import { SignedIn, SignedOut, SignInButton, SignOutButton, User } from '@asgardeo/vue'
</script>
<template>
<div>
<SignedIn>
<User v-slot="{ user, isLoading }">
<div v-if="!isLoading" class="user-info">
<h1>Welcome, </h1>
<p>Email: </p>
</div>
<div v-else>
Loading user information...
</div>
</User>
<SignOutButton />
</SignedIn>
<SignedOut>
<SignInButton />
</SignedOut>
</div>
</template>
Run your application and test the sign-in functionality. You should see a “Sign In” button when you’re not signed in, and clicking it will redirect you to the Asgardeo sign-in page.
# Using npm
npm run dev
# Using pnpm
pnpm dev
# Using yarn
yarn dev
Open your browser and navigate to http://localhost:5173 (or the port shown in your terminal). Click the “Sign In” button to test the authentication flow.
The SDK automatically handles the OAuth callback redirect. Make sure your application loads correctly after returning from Asgardeo. For custom callback handling, you can use the Callback component:
<script setup lang="ts">
import { Callback } from '@asgardeo/vue'
</script>
<template>
<div>
<Callback />
</div>
</template>
🎉 Congratulations! You’ve successfully integrated Asgardeo authentication into your Vue app.
useUser, useOrganization, etc.)app.use(AsgardeoPlugin, { ... }) before mounting your appuseUser) inside a component wrapped with AsgardeoProviderIf you encounter issues: