skills/clerk-nuxt-patterns/SKILL.md
Nuxt 3 auth patterns with @clerk/nuxt - middleware, composables, server API routes, SSR. Triggers on: Nuxt auth, useAuth composable, clerkMiddleware Nuxt, server API Clerk, Nuxt route protection.
npx skillsauth add awfixers-stuff/opencode-config clerk-nuxt-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| Task | Reference | |------|-----------| | Protect routes with middleware | references/nuxt-middleware.md | | Auth in server API routes (Nitro) | references/server-api-routes.md | | useAuth / useUser in components | references/composables.md | | SSR-safe auth patterns | references/ssr-auth.md |
| Reference | Description |
|-----------|-------------|
| references/nuxt-middleware.md | Route protection, clerkMiddleware() |
| references/server-api-routes.md | Nitro server route auth |
| references/composables.md | useAuth, useUser, useClerk |
| references/ssr-auth.md | SSR hydration, server vs client |
npm install @clerk/nuxt
.env:
NUXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_...
NUXT_CLERK_SECRET_KEY=sk_...
nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@clerk/nuxt'],
})
This single line auto-configures middleware, plugins, and component auto-imports.
@clerk/nuxt auto-imports all Clerk components and composables — no explicit imports needed in <script setup>.
useAuth, useUser) — client-side reactive, inside <script setup>clerkClient) — Nitro server routes, event.context.authclerkMiddleware) — auto-registered, use auth().protect() to lock routes<!-- pages/dashboard.vue -->
<script setup lang="ts">
definePageMeta({ middleware: 'auth' })
const { userId } = useAuth()
</script>
<template>
<Show when="signed-in">
<p>Hello {{ userId }}</p>
</Show>
</template>
definePageMeta({ middleware: 'auth' })uses the built-in auth middleware from@clerk/nuxt.
| Symptom | Cause | Fix |
|---------|-------|-----|
| Composables return undefined on server | useAuth is client-only | Use event.context.auth in server routes |
| Route not protected | Missing middleware: 'auth' meta | Add definePageMeta({ middleware: 'auth' }) |
| clerkClient not available | Wrong import path | Import from @clerk/nuxt/server |
| Hydration mismatch | Rendering auth state before mounted | Wrap in <ClientOnly> or check isLoaded |
| Env vars not picked up | Wrong prefix | Nuxt requires NUXT_PUBLIC_ for public, NUXT_ for server |
<script setup lang="ts">
const { orgId, orgRole } = useAuth()
</script>
<template>
<div v-if="orgId">
<p>Org: {{ orgId }}</p>
<p v-if="orgRole === 'org:admin'">Admin panel</p>
</div>
<div v-else>
<OrganizationSwitcher />
</div>
</template>
clerk-setup - Initial Clerk installclerk-custom-ui - Custom flows & appearanceclerk-orgs - B2B organizationsNuxt SDK
development
Use when starting dev servers, watchers, tilt, or any process expected to outlive the conversation. Provides zmx session management patterns for long-lived processes.
development
Zig testing skill for writing and running tests. Use when using zig build test, writing comptime tests, using test filters, working with test allocators to detect leaks, or using Zig's built-in fuzz testing (0.14+). Activates on queries about Zig tests, zig test, zig build test, comptime testing, test allocators, Zig fuzz testing, or detecting memory leaks in Zig tests.
development
Zig debugging skill. Use when debugging Zig programs with GDB or LLDB, interpreting Zig runtime panics, using std.debug.print for tracing, configuring debug builds, or debugging Zig programs in VS Code. Activates on queries about debugging Zig, Zig panics, zig gdb, zig lldb, std.debug.print, Zig stack traces, or Zig error return traces.
tools
Zig cross-compilation skill. Use when cross-compiling Zig programs to different targets, using Zig's built-in cross-compilation for embedded, WASM, Windows, ARM, or using zig cc to cross-compile C code without a system cross-toolchain. Activates on queries about Zig cross-compilation, zig target triples, zig cc cross-compile, Zig embedded targets, or Zig WASM.