Skip to main content
Docs

Vue Quickstart

This tutorial assumes that you're using Vue 3 with TypeScript.

Create a new Vue app

If you don't already have a Vue app, run the following commands to create a new one using Vite:

terminal
npm create vite@latest clerk-vue -- --template vue-ts
cd clerk-vue
npm install
terminal
pnpm create vite clerk-vue --template vue-ts
cd clerk-vue
pnpm install
terminal
yarn create vite clerk-vue --template vue-ts
cd clerk-vue
yarn install
terminal
bunx create-vite clerk-vue --template vue-ts
cd clerk-vue
bun install

Install @clerk/vue

The Clerk Vue SDK gives you access to prebuilt components, composables, and helpers to make user authentication easier.

Run the following command to install the SDK:

terminal
npm install @clerk/vue
terminal
pnpm add @clerk/vue
terminal
yarn add @clerk/vue
terminal
bun add @clerk/vue
.env
VITE_CLERK_PUBLISHABLE_KEY=YOUR_PUBLISHABLE_KEY

Add clerkPlugin to your app

clerkPlugin provides session and user context to Clerk's components and composables. It's required to pass your Clerk as an option. You can add an if statement to check that the key is imported properly. This prevents the app from running without the Publishable Key and catches TypeScript errors.

The clerkPlugin accepts optional options, such as { signInForceRedirectUrl: '/dashboard' }.

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

const PUBLISHABLE_KEY = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY

if (!PUBLISHABLE_KEY) {
  throw new Error('Add your Clerk Publishable Key to the .env file')
}

const app = createApp(App)
app.use(clerkPlugin, { publishableKey: PUBLISHABLE_KEY })
app.mount('#app')

Create a header with Clerk components

You can control which content signed-in and signed-out users can see with Clerk's prebuilt control components. The following example creates a header using the following components:

src/App.vue
<script setup lang="ts">
import { SignedIn, SignedOut, SignInButton, SignUpButton, UserButton } from '@clerk/vue'
</script>

<template>
  <header>
    <!-- Show the sign-in and sign-up buttons when the user is signed out -->
    <SignedOut>
      <SignInButton />
      <SignUpButton />
    </SignedOut>
    <!-- Show the user button when the user is signed in -->
    <SignedIn>
      <UserButton />
    </SignedIn>
  </header>
</template>

Run your project

Run your project with the following command:

terminal
npm run dev
terminal
pnpm run dev
terminal
yarn dev
terminal
bun run dev

Create your first user

  1. Visit your app's homepage at http://localhost:5173.
  2. Select "Sign up" on the page and authenticate to create your first user.

Next steps

Learn more about Clerk components, how to customize them, and how to use Clerk's client-side helpers using the following guides.

Prebuilt components

Learn more about Clerk's suite of components that let you quickly add authentication to your app.

Customization & localization

Learn how to customize and localize Clerk components.

Client-side helpers (composables)

Learn more about Clerk's client-side helpers and how to use them.

Update Clerk options at runtime

Learn how to update Clerk's options at runtime in your Vue app.

Feedback

What did you think of this content?

Last updated on

GitHubEdit on GitHub