The `@authdog/vue` SDK adds browser authentication state to Vue 3 through a provider and composables. It also exposes low-level cookie/logout helpers for standard Web `Request` objects. It does not ship a Nuxt module or adapter.

## Install

```package-install
@authdog/vue
```

Requires Vue `^3.5`. The package ships three entry points: `@authdog/vue` (composables), `@authdog/vue/client` (provider), and `@authdog/vue/server` (SSR).

## Wrap your app

Every composable reads from `AuthdogProvider`, so mount it at the root:

```vue
<script setup lang="ts">
import { AuthdogProvider } from "@authdog/vue/client"
</script>

<template>
  <AuthdogProvider>
    <YourApp />
  </AuthdogProvider>
</template>
```

On load the provider accepts a `?token=` only when it has three JWT-shaped segments, stores it in `localStorage`, strips it from the URL, and reloads. This regex is not signature, issuer, audience, or expiry validation. The real validation happens when `fetchUser()` calls Authdog userinfo.

## Composables

- `useUser()`: `{ user, isLoading, error, isAuthenticated, fetchUser(publicKey) }`
- `useSession()`: `{ session, isLoading }` where `session` is `{ token, isAuthenticated }`
- `useSignIn()`: `{ signIn(publicKey, redirectUrl?), isLoading, error }`
- `useSignUp()`, `useSignOut()`: `{ signOut, isLoading, error }`
- `useOrganization()`, `useOrganizationList()`: the caller's tenants
- `useAuthz()`: `{ permissions, hasPermission, hasAnyPermission, hasAllPermissions, ... }`

`useUser().fetchUser(publicKey)` and `useSignIn().signIn(publicKey, ...)` take your environment's **public key** (`pk_...`) explicitly:

```vue
<script setup lang="ts">
import { onMounted } from "vue"
import { useUser } from "@authdog/vue"

const { user, isLoading, fetchUser } = useUser()
onMounted(() => fetchUser(import.meta.env.VITE_AUTHDOG_PUBLIC_KEY))
</script>
```

## Server helpers

`createAuthdogServer` reads the raw `authdog-session` cookie and provides logout. It requires both keys, but currently has no server-side `getUser` method and does not validate the session:

```ts
import { createAuthdogServer } from "@authdog/vue/server"

const authdog = createAuthdogServer({
  publicKey: process.env.AUTHDOG_PUBLIC_KEY!,
  secretKey: process.env.AUTHDOG_SECRET_KEY!,
})

// authdog.getSession(request), authdog.logout(request)
```

No cookie callback exchange is included. In Nuxt, build server integration explicitly: validate the bearer token with a [backend SDK](/docs/backend), set an HttpOnly cookie if needed, and enforce [authorization](/docs/concepts/authorization) in server routes. Treat provider/composable state and `getSession()` as untrusted input.

## Next steps

- [Sign up & sign in](/docs/authentication): the flows the provider drives.
- [Backend requests](/docs/backend): validate sessions on your API.
- [Roles & permissions](/docs/permissions): the data behind `useAuthz`.
