clerk-nuxt-patterns

Implements Nuxt 3 authentication patterns with @clerk/nuxt middleware, composables, and server routes.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/Rajaryan1726/ai-code-review-system --skill clerk-nuxt-patterns-rajaryan1726
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: clerk-nuxt-patterns
Source: https://github.com/Rajaryan1726/ai-code-review-system/tree/main/client/.agents/skills/clerk-nuxt-patterns
Command: npx skills add https://github.com/Rajaryan1726/ai-code-review-system --skill clerk-nuxt-patterns-rajaryan1726

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @clerk/nuxt, and includes references (resource) components.

What problem does it solve? Adding authentication to a Nuxt 3 app with Clerk involves several distinct surfaces — route middleware, Vue composables, Nitro server API routes, and SSR hydration — and mixing them up causes common bugs like undefined composables on the server, hydration mismatches, and unprotected routes. This Skill provides the correct pattern for each surface. ## Core Features & Use Cases - Route Protection: Apply the built-in auth middleware via definePageMeta or write custom route middleware with useAuth and navigateTo redirects. - Server API Auth: Secure Nitro server routes using event.context.auth and clerkClient from @clerk/nuxt/server, returning 401/403 errors correctly. - Component & SSR Patterns: Use auto-imported composables (useAuth, useUser, useClerk) in <script setup>, handle loading states, and avoid hydration mismatches. - Use Case: You are building a Nuxt SaaS dashboard and need to protect /dashboard, expose a /api/user-data endpoint that returns 401 for anonymous requests, and display the signed-in user's profile — this Skill gives the exact code pattern for each. ## Quick Start Ask the assistant to protect the /dashboard route in your Nuxt 3 app with Clerk so unauthenticated users are redirected to the sign-in page.

Frequently Asked Questions about clerk-nuxt-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I protect a route in Nuxt 3 with Clerk?▼

Add definePageMeta({ middleware: 'auth' }) to the page component. The @clerk/nuxt module auto-registers this auth middleware, which redirects unauthenticated users to the sign-in page before the page renders.

How do I get the current user in a Nuxt server API route?▼

Read event.context.auth inside a Nitro defineEventHandler to get userId, then call clerkClient(event).users.getUser(userId) imported from @clerk/nuxt/server for full profile data. Throw createError({ statusCode: 401 }) when userId is missing.

Why does useAuth return undefined on the server in Nuxt?▼

The useAuth and useUser composables are client-side reactive and do not work in Nitro server routes. On the server, use event.context.auth instead, which @clerk/nuxt populates automatically for all server routes.

Does @clerk/nuxt support organization switching and roles?▼

Yes. Read orgId and orgRole from useAuth() to scope content by organization, and render the auto-imported <OrganizationSwitcher /> component so users can switch orgs. Check orgRole === 'org:admin' for admin-only UI.

How do I fix Clerk hydration mismatch errors in Nuxt SSR?▼

Hydration mismatches happen when auth-dependent content renders differently on server and client. Wrap auth-gated content in <ClientOnly> or gate rendering on the isLoaded flag from useAuth. Pages using the auth middleware rarely need this since redirects happen server-side.

What environment variables does @clerk/nuxt require?▼

Set NUXT_PUBLIC_CLERK_PUBLISHABLE_KEY for the public key and NUXT_CLERK_SECRET_KEY for the server secret. Nuxt requires the NUXT_PUBLIC_ prefix for client-exposed values; wrong prefixes are a common cause of keys not being picked up.