Skip to main content

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.

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

Install @clerk/nuxt

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

Run the following command to install the SDK:

npm install @clerk/nuxt
pnpm add @clerk/nuxt
yarn add @clerk/nuxt
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 when="signed-out">
      <SignInButton />
      <SignUpButton />
    </Show>
    <Show when="signed-in">
      <UserButton />
    </Show>
  </header>

  <main>
    <NuxtPage />
  </main>
</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:3000.
  2. Select "Sign up" on the page and authenticate to create your first user.

Next steps

Explore the most relevant next steps for your SDK using the following guides.

Prebuilt components

Learn how to add Clerk's prebuilt authentication and user-management UI to your app.

Build custom flows

Learn how to build custom user interfaces entirely from scratch using the Clerk API.

Protect content and read user data

Learn how to use Clerk's helpers to protect content and read user data in your app.

Protect routes using clerkMiddleware()

Learn how to protect specific routes from unauthenticated users.

More to explore

Explore additional Clerk features that help you build, manage, and grow your application.

  • Organizations - Organizations are shared accounts that let teams collaborate, manage members and roles, and control access to shared resources.
  • Billing - Billing enables you to manage subscriptions, free trials, payments, plans, and billing-related webhook events for B2C and B2B applications.
  • Waitlist - Waitlist lets you collect signups and control access to new products or features before launch through a simple, integrated workflow.

Feedback

What did you think of this content?

Last updated on