Skip to main content
Docs

Nuxt Quickstart

Create a new Nuxt app

If you don't already have a Nuxt app, run the following commands to create a new one.

terminal
npm create nuxt@latest clerk-nuxt
cd clerk-nuxt
npm install
terminal
pnpm create nuxt clerk-nuxt
cd clerk-nuxt
pnpm install
terminal
yarn create nuxt clerk-nuxt
cd clerk-nuxt
yarn install
terminal
bunx create-nuxt clerk-nuxt
cd clerk-nuxt
bun install

Install @clerk/nuxt

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

Run the following command to install the SDK:

terminal
npm install @clerk/nuxt
terminal
pnpm add @clerk/nuxt
terminal
yarn add @clerk/nuxt
terminal
bun add @clerk/nuxt
.env
NUXT_PUBLIC_CLERK_PUBLISHABLE_KEY=YOUR_PUBLISHABLE_KEY
NUXT_CLERK_SECRET_KEY=YOUR_SECRET_KEY

Configure nuxt.config.ts

To enable Clerk in your Nuxt app, add @clerk/nuxt to your modules array in nuxt.config.ts. This automatically configures Clerk's middleware and plugins and imports Clerk's components.

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@clerk/nuxt'],
})

Create a header with Clerk components

Nuxt 3 automatically imports and makes all components in the components/ directory globally available without requiring explicit imports. See the Nuxt docs for details.

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:

app/app.vue
<script setup lang="ts">
// Components are automatically imported
</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>

  <main>
    <NuxtPage />
  </main>
</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:3000.
  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.

Protect API routes using clerkMiddleware()

Learn how to protect specific API routes from unauthenticated users.

Protect content and read user data

Learn how to use Clerk's composables and helpers to access the session and user data in your Nuxt app.

Client-side helpers

Learn more about Nuxt client-side helpers and how to use them.

Customization & localization

Learn how to customize and localize Clerk components.

Prebuilt components

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

Feedback

What did you think of this content?

Last updated on

GitHubEdit on GitHub