About clerk-nuxt-patterns
clerk-nuxt-patterns is a skill for developers integrating Clerk into Nuxt projects, covering route protection, Nitro server routes, composables, and SSR authentication. It describes module auto-configuration and the different use of auth state on the server and client.
Key features
- 01Protect Nuxt routes
- 02Handle auth in Nitro routes
- 03Use authentication composables
- 04Explain SSR and client auth patterns
- 05Describe module auto-configuration
Use cases
- 01Restrict access to Nuxt page routes
- 02Read auth details in Nitro API routes
- 03Use user and auth state in components
- 04Troubleshoot SSR hydration or environment variable issues
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ midudev/ autoskills --skill clerk-nuxt-patternsAfter installing, type/clerk-nuxt-patternsin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
evals/evals.jsonreferences/composables.mdnuxt-middleware.mdserver-api-routes.mdssr-auth.mdtemplates/nuxt-basic-auth/app.vuenuxt.config.tspackage.jsonDetails
From the project READMENuxt Patterns
What Do You Need?
| 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 |
References
| 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 |
Setup
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.
Mental Model
@clerk/nuxt auto-imports all Clerk components and composables — no explicit imports needed in <script setup>.
- Composables (
useAuth,useUser) — client-side reactive, inside<script setup> - Server routes (
clerkClient) — Nitro server routes,event.context.auth - Middleware (
clerkMiddleware) — auto-registered, useauth().protect()to lock routes
Minimal Pattern
<!-- 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.
Common Pitfalls
| 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 |
Org-Aware Pattern
<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>
See Also
clerk-setup- Initial Clerk installclerk-custom-ui- Custom flows & appearanceclerk-orgs- B2B organizations
Docs
Comments
Markdown supported