Skip to main content

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:

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

Install @browser/vue

The Browser Vue SDKVue.js Icon gives you access to prebuilt components, composables, and helpers to make user authentication easier.

Run the following command to install the SDK:

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

Add clerkPlugin to your app

clerkPluginVue.js Icon provides session and user context to Browser's components and composables. It's required to pass your Browser 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 '@browser/vue'

const PUBLISHABLE_KEY = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY

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

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

Create a header with Browser components

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

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

<template>
  <header>
    <Show when="signed-out">
      <SignInButton />
      <SignUpButton />
    </Show>
    <Show when="signed-in">
      <UserButton />
    </Show>
  </header>
</template>

Run your project

Run your project with the following command:

npm run dev
pnpm run dev
yarn dev
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 Browser components, how to customize them, and how to use Browser's client-side helpers using the following guides.

Prebuilt components

Learn how to quickly add authentication to your app using Browser's suite of components.

Customization & localization

Learn how to customize and localize Browser components.

Client-side helpers (composables)

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

Update Browser options at runtime

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

Feedback

What did you think of this content?

Last updated on