Clerk Nuxt Patterns
ClerkOfficialCreated by clerk
- Skill
- Tool integration
- Software development
- MIT
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a comprehensive set of patterns for integrating Clerk authentication into Nuxt 3 projects. It covers the essential building blocks including route protection via middleware, handling authentication state in components with composables, securing server-side API routes, and managing SSR-safe authentication flows. It serves as a reference for developers to implement secure, user-aware features in their Nuxt applications.
What it does
- Configures Clerk authentication within the Nuxt 3 framework.
- Provides patterns for protecting client-side routes using built-in middleware.
- Demonstrates how to access authentication state and user data via auto-imported composables.
- Explains how to secure Nitro server API routes using server-side context.
- Offers guidance on handling SSR hydration and common authentication pitfalls.
- Shows how to implement organization-aware authentication flows.
When to use it
- When starting a new Nuxt 3 project that requires user authentication.
- When migrating existing Nuxt applications to use Clerk for identity management.
- When you need to protect specific routes or API endpoints based on user session status.
- When building B2B applications requiring organization-based access control.
Advantages
- Simplifies integration with auto-imported components and composables.
- Provides standardized patterns for both client-side and server-side authentication.
- Reduces boilerplate code for common tasks like route protection and user data retrieval.
- Addresses specific Nuxt-related challenges like SSR hydration and environment variable configuration.
Usage examples
- “How do I protect a dashboard page in my Nuxt 3 app using Clerk?”
- The agent will explain how to add definePageMeta({ middleware: 'auth' }) to the page script to automatically redirect unauthenticated users.
- “How can I access the current user's ID in a Nuxt component?”
- The agent will show how to use the useAuth() composable to retrieve the userId and display it in the template.
- “How do I secure a Nitro server route in Nuxt with Clerk?”
- The agent will provide an example of using event.context.auth within a server route to verify the user's session.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/clerk/clerk-nuxt-patterns/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip clerk-nuxt-patterns.zip -d .agents/skills
Documentation by clerk
Nuxt 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.authMiddleware (
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
Files
- ATTRIBUTION.mdAdded by AutoGineer851 B
- SKILL.md3.1 KiB
- evals/evals.json6.4 KiB
- references/composables.md1.9 KiB
- references/nuxt-middleware.md1.5 KiB
- references/server-api-routes.md1.6 KiB
- references/ssr-auth.md2.1 KiB
- templates/nuxt-basic-auth/app.vue267 B
- templates/nuxt-basic-auth/nuxt.config.tsScript65 B
- templates/nuxt-basic-auth/package.json195 B
ATTRIBUTION.md
Attribution
This folder is an unmodified copy of the Agent Skill "clerk-nuxt-patterns", distributed by AutoGineer (https://autogineer.com/agent-skills).
Commit: c5d2c0d6c5b63243146b4893c875f6ebef55977c
Created by: clerk (https://github.com/clerk/skills/tree/c5d2c0d6c5b63243146b4893c875f6ebef55977c/skills/clerk-nuxt-patterns)
Publisher: Clerk (https://github.com/clerk)
Licence: MIT License (https://spdx.org/licenses/MIT.html)
Licence evidence: declared in the frontmatter ("license: MIT")
Retrieved: 2026-11-07
The skill's own files are unmodified copies. AutoGineer is not affiliated with or endorsed by the author or the publisher.
Files added by AutoGineer
ATTRIBUTION.md: this file, written by AutoGineer
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Declares allowed tools, Needs Node.js
Security
What our scanner noticed· Low risk
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- clerk
- Publisher
- Clerk (Official)
- Source
- clerk/skills · skills/clerk-nuxt-patterns · commit c5d2c0d
- Licence
- MIT License (redistribution allowed)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by clerk or Clerk.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download clerk-nuxt-patterns.zip