clerk-nuxt-patterns

Implement Clerk authentication patterns in Nuxt 3 apps including middleware, composables, and server routes.

Updated Sep 19, 2026
One-click install
npx skills add https://github.com/paramcodes/autobro --skill clerk-nuxt-patterns-paramcodes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: clerk-nuxt-patterns
Source: https://github.com/paramcodes/autobro/tree/main/.agents/skills/clerk-nuxt-patterns
Command: npx skills add https://github.com/paramcodes/autobro --skill clerk-nuxt-patterns-paramcodes

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Adding authentication to a Nuxt 3 application involves many moving parts: route protection, server API auth, SSR hydration, and organization support. This Skill provides proven patterns for integrating @clerk/nuxt so you avoid common pitfalls like hydration mismatches, undefined composables on the server, and unprotected routes. ## Core Features & Use Cases - Route Protection: Use the built-in auth middleware with definePageMeta or create custom route middleware for org-scoped access control. - Server API Auth: Access event.context.auth and clerkClient in Nitro server routes to return 401/403 responses and fetch user data securely. - Composables & SSR: Use auto-imported useAuth, useUser, and useClerk composables with SSR-safe patterns that prevent hydration mismatches. - Use Case: You are building a Nuxt SaaS dashboard and need to protect /dashboard, expose an authenticated /api/user-data endpoint, and add organization switching in the header. This Skill gives you the exact middleware, server route, and component patterns to implement all three. ## Quick Start Ask the AI 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 routes 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 to check authentication in a Nuxt server API route?▼

Access event.context.auth inside a Nitro event handler to get the userId, and throw createError({ statusCode: 401 }) when it is missing. For full user data, import clerkClient from @clerk/nuxt/server and call clerkClient(event).users.getUser(userId).

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

The useAuth composable is client-reactive and not available 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?▼

Yes, the auto-imported OrganizationSwitcher component lets users switch organizations, and useAuth exposes orgId, orgRole, and orgSlug for scoping content. You can conditionally render admin UI by checking orgRole === 'org:admin'.

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

Hydration mismatches happen when auth-dependent content renders differently on server and client. Wrap auth-gated content in <ClientOnly> or check isLoaded from useAuth before rendering; protected pages using middleware rarely need this since the redirect happens server-side.