clerk-vue-patterns

作成者: clerk

Vue 3パターンとClerk — コンポーザブル(useAuth、useUser、

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

Vue Patterns

SDK: @clerk/vue v2+ (Vue 3). For Nuxt, use clerk-nuxt-patterns.

What Do You Need?

TaskReference
Composables: useAuth, useUser, useOrganizationreferences/composables.md
Vue Router navigation guardsreferences/vue-router-guards.md
Pinia store with auth statereferences/pinia-integration.md

Mental Model

Vue uses composables from @clerk/vue:

  • useAuth() — reactive isSignedIn, userId, signOut
  • useUser() — reactive user object
  • useClerk() — full Clerk instance for advanced operations
  • useOrganization() — reactive organization, membership

Setup

Vue (Plain)

// main.ts
import { clerkPlugin } from '@clerk/vue'
import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App)
app.use(clerkPlugin, {
  publishableKey: import.meta.env.VITE_CLERK_PUBLISHABLE_KEY,
})
app.mount('#app')

Composables Usage

<script setup lang="ts">
import { useAuth, useUser } from '@clerk/vue'

const { isSignedIn, userId, signOut } = useAuth()
const { user } = useUser()
</script>

<template>
  <div v-if="isSignedIn">
    <p>Hello {{ user?.firstName }}</p>
    <button @click="signOut()">Sign Out</button>
  </div>
  <SignInButton v-else />
</template>

Org Switching

<script setup lang="ts">
import { useOrganizationList } from '@clerk/vue'

const { userMemberships, setActive } = useOrganizationList()
</script>

<template>
  <button
    v-for="mem in userMemberships.data ?? []"
    :key="mem.organization.id"
    @click="setActive({ organization: mem.organization.id })"
  >
    {{ mem.organization.name }}
  </button>
</template>

Common Pitfalls

SymptomCauseFix
Composables return undefinedNot inside ClerkProvider treeEnsure app.use(clerkPlugin, { publishableKey }) is called
userId reactive but not updatingDestructuring loses reactivityUse const { userId } = useAuth() (toRefs-style composable, reactive)

Import Map

WhatImport
Composables@clerk/vue
Plugin setup@clerk/vue
Components@clerk/vue

See Also

  • clerk-setup - Initial Clerk install
  • clerk-custom-ui - Custom flows & appearance
  • clerk-orgs - B2B organizations

Docs

clerkのその他のスキル

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
サブスクリプション管理のためのClerk Billing - ClerkのPricingTableをレンダリング
clerk-nextjs-patterns
clerk
Clerkを使用した認証、ミドルウェア、Server Actions、ユーザースコープキャッシングのための高度なNext.jsパターン。サーバーサイドのawait auth()とクライアントサイドのuseAuth()フックを区別します。これらを混在させることはよくある破壊的なミスです。ミドルウェア戦略(public-first vs protected-first)、APIルート保護、適切なHTTPステータスコード(401 vs 403)をカバーします。unstable_cacheを使用したユーザースコープキャッシングパターンと、Server Actionsを不正な変更から保護する方法を含みます。Core 2互換性を提供します...
clerk-expo-patterns
clerk
Expo / React NativeパターンとClerk — SecureStoreトークンキャッシュ、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バイナリは、ClerkのBackend APIおよびPlatform APIへの事前認証済みゲートウェイであり、プロジェクトレベルのツール(認証、リンク、環境変数の取得、インスタンス設定)も提供します。ユーザーがClerkリソースに関わる何かを尋ねた場合、手動でcurlを使う代わりに、まずclerkを使用してください。
clerk-cli
clerk
clerk バイナリは、Clerk のバックエンド API およびプラットフォーム API への事前認証済みゲートウェイであり、プロジェクトレベルのツール(認証、リンク、環境変数のプル、インスタンス設定)も提供します。ユーザーが Clerk リソースに関連する何かを尋ねた場合、手動で curl を使う代わりに、まず clerk を使用してください。
clerk-astro-patterns
clerk
Clerkを使ったAstroパターン — ミドルウェア、SSRページ、アイランドコンポーネント