What problem does it solve?
Many Nuxt 3 applications need a secure, SSR-safe authentication model that protects both client routes and server API endpoints without fragile client-only checks. This Skill documents patterns for integrating Clerk via @clerk/nuxt to enforce route protection, authenticate Nitro server routes, and safely surface user and organization context in components and APIs.
Core Features & Use Cases
- Route protection with middleware: Use the built-in auth middleware or create custom route middleware to redirect unauthenticated users to a sign-in page.
- Client composables: Use useAuth, useUser, and useClerk in components for reactive auth state, user profile rendering, and client actions.
- Server API guards: Read auth from event.context.auth or use clerkClient/getAuth in Nitro server routes to return 401/403 and fetch user data securely.
- SSR and hydration safety: Patterns to avoid hydration mismatches and ensure middleware runs server-side so protected pages render correctly.
- Org-aware workflows: Examples for reading orgId/orgRole from auth and scoping server and UI content accordingly.
Quick Start
Install @clerk/nuxt, add it to nuxt.config, set NUXT_PUBLIC_CLERK_PUBLISHABLE_KEY and NUXT_CLERK_SECRET_KEY in your environment, then protect a page by adding definePageMeta({ middleware: 'auth' }).