Skip to content

vue-oidc-contextOpenID Connect for Vue 3

A lightweight, fully typed wrapper around oidc-client-ts — react-oidc-context, ported to Vue idioms.

Install

bash
pnpm add @dlukt/vue-oidc-context oidc-client-ts

Published under the @dlukt scope — the unscoped npm name vue-oidc-context belongs to an unrelated package.

At a glance

ts
// main.ts
import { createApp } from "vue";
import { createOidcAuth } from "@dlukt/vue-oidc-context";
import App from "./App.vue";

const auth = createOidcAuth({
  authority: "https://demo.duendesoftware.com",
  client_id: "interactive.public",
  redirect_uri: `${window.location.origin}/`,
  onSigninCallback: () => {
    window.history.replaceState({}, document.title, window.location.pathname);
  },
});

createApp(App).use(auth).mount("#app");
vue
<script setup lang="ts">
import { useAuth } from "@dlukt/vue-oidc-context";

const { user, isAuthenticated, isLoading, signinRedirect, signoutRedirect } =
  useAuth();
</script>

<template>
  <div v-if="isLoading">Signing you in/out…</div>
  <template v-else-if="isAuthenticated">
    Hello {{ user?.profile.name }}
    <button @click="signoutRedirect()">Log out</button>
  </template>
  <button v-else @click="signinRedirect()">Log in</button>
</template>

Released under the MIT License.