clerk-nuxt-patterns

tarafından clerk

@clerk/nuxt ile Nuxt 3 kimlik doğrulama desenleri - middleware, composable'lar, sunucu

npx skills add https://github.com/clerk/skills --skill clerk-nuxt-patterns

Nuxt Patterns

What Do You Need?

TaskReference
Protect routes with middlewarereferences/nuxt-middleware.md
Auth in server API routes (Nitro)references/server-api-routes.md
useAuth / useUser in componentsreferences/composables.md
SSR-safe auth patternsreferences/ssr-auth.md

References

ReferenceDescription
references/nuxt-middleware.mdRoute protection, clerkMiddleware()
references/server-api-routes.mdNitro server route auth
references/composables.mduseAuth, useUser, useClerk
references/ssr-auth.mdSSR 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, use auth().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

SymptomCauseFix
Composables return undefined on serveruseAuth is client-onlyUse event.context.auth in server routes
Route not protectedMissing middleware: 'auth' metaAdd definePageMeta({ middleware: 'auth' })
clerkClient not availableWrong import pathImport from @clerk/nuxt/server
Hydration mismatchRendering auth state before mountedWrap in <ClientOnly> or check isLoaded
Env vars not picked upWrong prefixNuxt 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 install
  • clerk-custom-ui - Custom flows & appearance
  • clerk-orgs - B2B organizations

Docs

Nuxt SDK

clerk tarafından daha fazla skill

mosaic
clerk
Work on Mosaic UI: styling a component with slot recipes (`defineSlotRecipe` / `useRecipe` / slots / variants), or building a flow — authoring a state machine…
clerk-billing
clerk
Abonelik yönetimi için Clerk Billing - Clerk'in PricingTable'ını render eder
clerk-nextjs-patterns
clerk
We need to translate the given English text into Turkish, preserving the name "clerk-nextjs-patterns" if it appears. The text is a description of an agent skill. We must not add any extra commentary, labels, or formatting. The translation should be accurate and natural in Turkish, keeping technical terms like "Next.js", "Clerk", "auth()", "useAuth()", "unstable_cache", "Server Actions", "API route", "HTTP status codes", "401", "403", "Core 2" as is. Also preserve "middleware", "authentication", "user-scoped caching", etc. but translate the surrounding words. The text: "Advanced Next.js patterns for authentication, middleware, Server Actions, and user-scoped caching with Clerk. Distinguishes server-side await auth() from client-side useAuth() hook; mixing them is a common breaking mistake Covers middleware strategies (public-first vs protected-first), API route protection, and proper HTTP status codes (401 vs 403) Includes user-scoped caching patterns with unstable_cache
clerk-expo-patterns
clerk
Expo / React Native desenleri Clerk ile — SecureStore token önbelleği, OAuth
changesets
clerk
Create or refresh a `.changeset/<slug>.md` for the current branch, or report that none is required. Triggers on "/changesets create", "add a changeset",…
clerk
clerk
clerk ikili dosyası, Clerk'in Arka Uç API'si ve Platform API'sine önceden kimlik doğrulaması yapılmış bir ağ geçididir ve ayrıca proje düzeyinde araçlar (kimlik doğrulama, bağlantı, ortam çekmeleri, örnek yapılandırması) içerir. Kullanıcı Clerk kaynağına dokunan bir şey sorduğunda, elle curl yazmak yerine önce clerk'ı kullanın.
clerk-cli
clerk
clerk binary, Clerk'in Backend API ve Platform API'sine önceden kimlik doğrulaması yapılmış bir ağ geçididir ve ayrıca proje düzeyinde araçlar (kimlik doğrulama, bağlantı, env çekme, örnek yapılandırması) içerir. Kullanıcı bir Clerk kaynağına dokunan herhangi bir şey sorduğunda, elle curl yazmak yerine önce clerk'a başvurun.
clerk-astro-patterns
clerk
Clerk ile Astro desenleri — middleware, SSR sayfaları, ada bileşenleri,