clerk-vue-patterns

โดย clerk

รูปแบบ Vue 3 กับ Clerk — composables (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

Skills เพิ่มเติมจาก 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 สำหรับการจัดการการสมัครสมาชิก - แสดง PricingTable ของ Clerk
clerk-nextjs-patterns
clerk
รูปแบบ Next.js ขั้นสูงสำหรับการตรวจสอบสิทธิ์ มิดเดิลแวร์ Server Actions และการแคชตามขอบเขตผู้ใช้ด้วย Clerk แยกความแตกต่างระหว่าง auth() แบบฝั่งเซิร์ฟเวอร์ที่รอคอยผลลัพธ์กับ useAuth() hook ฝั่งไคลเอ็นต์ การผสมกันเป็นข้อผิดพลาดที่พบบ่อย ครอบคลุมกลยุทธ์มิดเดิลแวร์ (สาธารณะก่อนเทียบกับป้องกันก่อน) การป้องกันเส้นทาง API และรหัสสถานะ HTTP ที่เหมาะสม (401 เทียบกับ 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's Backend API และ Platform API พร้อมด้วยเครื่องมือระดับโปรเจกต์ (การรับรองความถูกต้อง การเชื่อมโยง การดึง env การกำหนดค่าอินสแตนซ์) เมื่อผู้ใช้ถามถึงสิ่งใดก็ตามที่เกี่ยวข้องกับทรัพยากร Clerk ให้ใช้ clerk ก่อนแทนที่จะเขียน curl ด้วยตนเอง
clerk-cli
clerk
ไบนารี clerk เป็นเกตเวย์ที่ผ่านการรับรองความถูกต้องล่วงหน้าไปยัง Clerk's Backend API และ Platform API พร้อมด้วยเครื่องมือระดับโปรเจกต์ (การตรวจสอบสิทธิ์ การเชื่อมโยง การดึง env การกำหนดค่าอินสแตนซ์) เมื่อผู้ใช้ถามถึงสิ่งใดก็ตามที่เกี่ยวข้องกับทรัพยากรของ Clerk ให้ใช้ clerk ก่อนแทนที่จะเขียน curl ด้วยตนเอง
clerk-astro-patterns
clerk
รูปแบบ Astro กับ Clerk — มิดเดิลแวร์, หน้า SSR, คอมโพเนนต์ไอส์แลนด์