All skills
clerk avatar

/clerk-vue-patterns

@7ad2635 official
by clerkclerk/skills83 stars
5

Vue 3 patterns with Clerk — composables (useAuth, useUser, useClerk, useOrganization), Vue Router guards, Pinia auth store integration. Triggers on: vue clerk, useAuth vue, clerk composables, vue router clerk guard, pinia auth clerk. For Nuxt, use clerk-nuxt-patterns instead.

Use this Skill: https://skilld.dev/gh/clerk/skills/clerk-vue-patterns

This session only. Nothing lands on disk.

referencesvue-router-guards.md

≈415 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Vue Router Guards

For plain Vue (without Nuxt), protect routes using navigation guards.

Global Before Guard

// router/index.ts
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: '/', component: Home },
    { path: '/sign-in', component: SignIn },
    { path: '/dashboard', component: Dashboard, meta: { requiresAuth: true } },
  ],
})

router.beforeEach(async (to) => {
  if (!to.meta.requiresAuth) return true

  const { userId } = useAuth()

  if (!userId.value) return '/sign-in'
  return true
})

Per-Route Guard with In-Component Guard

<script setup lang="ts">
import { useAuth } from '@clerk/vue'
import { useRouter } from 'vue-router'
import { watchEffect } from 'vue'

const { isSignedIn, isLoaded } = useAuth()
const router = useRouter()

watchEffect(() => {
  if (isLoaded.value && !isSignedIn.value) {
    router.replace('/sign-in')
  }
})
</script>

Org-Gated Route

router.beforeEach(async (to) => {
  if (!to.meta.requiresOrg) return true

  const { userId } = useAuth()
  const { organization } = useOrganization()

  if (!userId.value) return '/sign-in'
  if (!organization.value) return '/select-org'
  return true
})

CRITICAL

  • Call composables outside of the guard function body if possible — useAuth() is reactive and works outside components in Vue 3 (when called in setup context or at module level after plugin install)
  • isLoaded must be true before trusting isSignedIn — guard may fire before Clerk initializes
  • For Nuxt, prefer middleware/ instead of manual router guards

Source: SKILL.md on GitHub

No alerts16d4 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides legitimate Vue 3 patterns and templates for integrating Clerk authentication. It follows security best practices and contains no malicious code or exfiltration patterns.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 7ad2635. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 6 months ago
What it can do
Network
metadata
{
  "author": "clerk",
  "version": "1.0.0"
}
All 1 allowed tools
WebFetch
  • Vue
  • clerk
  • composables
  • authentication
  • vue-router
  • pinia
  • organizations

README badge

README badge for clerk/skills/clerk-vue-patterns

Provides Clerk auth composables and patterns for Vue 3, including useAuth, useUser, useOrganization, Vue Router guards, and Pinia store integration. Targets @clerk/vue v2+ and assumes you're building with plain Vue rather than Nuxt.

Generated from the current SKILL.md.

Does this skill cover Nuxt?
No. This skill targets Vue 3 with @clerk/vue. For Nuxt, use clerk-nuxt-patterns instead.
What composables does this skill teach?
useAuth, useUser, useClerk, and useOrganization — all from @clerk/vue v2+. Each provides reactive access to auth state, user data, and organization context.
Does this include Vue Router integration?
Yes. The skill covers Vue Router navigation guards for protecting routes based on auth state.
Can I use this with a Pinia store?
Yes. The skill includes a reference for integrating Clerk auth state with Pinia.
Why are my composables returning undefined?
Composables must be called inside the ClerkProvider tree. Ensure app.use(clerkPlugin, { publishableKey }) is invoked in main.ts.

Generated from the current SKILL.md. These answers refresh after source changes.