Wocha Docs

Nuxt SDK

Nuxt 3 module with server-side OAuth and encrypted cookie sessions.

@wocha/nuxt is the Nuxt 3 module for Wocha authentication using the BFF (backend-for-frontend) pattern. OAuth runs on Nitro server routes; sessions are stored in encrypted httpOnly cookies.

Installation

pnpm add @wocha/nuxt
Or scaffold with the CLI
npx @wocha/cli init --framework vue

Peer dependency: Nuxt >=3.10.

Setup

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ["@wocha/nuxt"],
  wochaAuth: {
    clientId: process.env.WOCHA_CLIENT_ID,
    clientSecret: process.env.WOCHA_CLIENT_SECRET,
    issuer: process.env.WOCHA_ISSUER,
    publicPaths: ["/", "/about"],
  },
});

Environment variables:

.env
WOCHA_CLIENT_ID=your-client-id
WOCHA_CLIENT_SECRET=your-client-secret
WOCHA_ISSUER=https://my-tenant.auth.wocha.ai

Server routes

The module auto-registers:

RoutePurpose
/api/auth/loginStart OAuth login
/api/auth/callbackOAuth callback
/api/auth/logoutEnd session
/api/auth/sessionPublic session JSON
/api/auth/switch-orgSwitch organisation

Route protection

<script setup lang="ts">
definePageMeta({ middleware: "auth" });
</script>

Composables (auto-imported)

<script setup lang="ts">
const { session, status } = useSession();
const user = useUser();
const { orgId, switchOrg } = useOrg();
const { signIn, signOut, hasPermission } = useWochaAuth();
</script>

Permission checks

const allowed = await hasPermission({
  resource: { type: "document", id: "doc_123" },
  permission: "read",
});

Learn more

On this page