---
title: "@xid-kit/vue"
description: "Vue 3 plugin, composables, and headless components on top of @xid-kit/core."
locale: "en"
---

> Documentation Index
> Fetch the locale documentation index at: https://xid.dev/en/llms.txt
> Use this file to discover all available pages before exploring further.

# @xid-kit/vue

## Status

Package status is **Current package**. Vue 3 plugin, composables, and headless components are implemented. A real IdP round-trip on production infrastructure is still pending manual verification.

## Plugin setup

Register `XidPlugin` once in `main.ts`. It creates an `XidClient` singleton, provides it via `XID_INJECTION_KEY`, and calls `client.load()` to hydrate session state.

```ts
// main.ts
import { createApp } from 'vue'
import { XidPlugin } from '@xid-kit/vue'
import App from './App.vue'

const app = createApp(App)
app.use(XidPlugin, { apiUrl: 'https://your-tenant.xid.dev' })
app.mount('#app')
```

## Composables

```ts
import { useAuth, useUser, useOrganization, useSession } from '@xid-kit/vue'

const auth = useAuth()
// auth.isLoaded / auth.isSignedIn / auth.userId
// auth.getToken()  -> Promise<Result<string, XidError>>
// auth.signOut()   -> Promise<Result<null, XidError>>

const userRef = useUser()
// userRef.value.isLoaded && userRef.value.isSignedIn -> userRef.value.user.id

const orgRef = useOrganization()
// orgRef.value.organization / orgRef.value.membership / orgRef.value.setActive()

const sessionRef = useSession()
// sessionRef.value.session / sessionRef.value.getToken()
```

## Components

```vue
<template>
  <SignInButton sign-in-url="/sign-in" redirect-url="/dashboard">Log in</SignInButton>
  <SignOutButton redirect-url="/">Log out</SignOutButton>

  <Protect role="org:admin">
<AdminPanel />
<template #fallback><p>Access denied.</p></template>
  </Protect>

  <Protect permission="org:member:read">
<MemberList />
  </Protect>
</template>

<script setup lang="ts">
import { SignInButton, SignOutButton, Protect } from '@xid-kit/vue'
</script>
```

## Exported API

| Export | Kind | Purpose |
| --- | --- | --- |
| `XidPlugin` | Vue plugin | app.use entry point; registers XidClient and calls client.load() |
| `createXidClient` | function | Factory that returns a standalone XidClient instance |
| `useXidClient` | composable | Returns the injected XidClient; throws if plugin is not registered |
| `XID_INJECTION_KEY` | InjectionKey | Symbol used to provide and inject the XidClient singleton |
| `useXid` | composable | Full state ref plus all client actions (UseXidReturn) |
| `useAuth` | composable | isLoaded, isSignedIn, userId, getToken, signOut |
| `useUser` | composable | Ref wrapping discriminated union on isLoaded / isSignedIn / user |
| `useOrganization` | composable | Active org, membership, and setActive action |
| `useSession` | composable | Active session and getToken action |
| `SignInButton` | component | Headless button that redirects to the sign-in URL on click |
| `SignOutButton` | component | Headless button that calls client.signOut() on click |
| `Protect` | component | Slot-based role and permission gate with default and fallback slots |

Source: https://xid.dev/sdks/vue/index.mdx
