Skip to content

useAsgardeo()

The useAsgardeo() composable of the WSO2 Identity Server Vue SDK (@asgardeo/vue) returns the authentication state and methods that <AsgardeoProvider> manages.

Overview

Call useAsgardeo() in the setup of any component rendered inside <AsgardeoProvider>. It returns an object with:

  • Reactive state as read-only refs: isSignedIn, isLoading, isInitialized, user and organization. Templates unwrap them; in scripts, read them with .value.
  • Methods to sign users in and out, read tokens and send authenticated requests.
  • Configuration values passed to <AsgardeoProvider>, such as clientId and baseUrl.

Usage

src/components/Header.vue
<script setup>
import { useAsgardeo } from '@asgardeo/vue'

const { isSignedIn, isLoading, user, signIn, signOut } = useAsgardeo()
</script>

<template>
  <p v-if="isLoading">Loading...</p>
  <div v-else-if="isSignedIn">
    <p>Signed in as {{ user?.userName }}</p>
    <button @click="signOut()">Sign out</button>
  </div>
  <button v-else @click="signIn()">Sign in</button>
</template>

To react to changes in a script, watch the refs:

Inside