🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More
Socket
Sign inDemoInstall
Socket

nuxt-clerk-utils

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuxt-clerk-utils

Auth utils for clerk

1.5.13
latest
Source
npm
Version published
Maintainers
0
Created
Source

nuxt-clerk-utils

npm version npm downloads License Nuxt

Clerk module that builds on top of vue-clerk

Features

  • Server middleware based on h3-clerk
  • Utilities for handling clerk webhooks

Requirements

This module only works with SSR (server-side rendering) enabled as it uses server API routes. You cannot use this module with nuxt generate.

Quick Setup

  • Add nuxt-clerk-utils
# Using pnpm
pnpm add -D nuxt-clerk-utils

# Using yarn
yarn add --dev nuxt-clerk-utils

# Using npm
npm install --save-dev nuxt-clerk-utils

  • Add nuxt-clerk-utils to nuxt.config.ts
export default defineNuxtConfig({
  modules: ["nuxt-clerk-utils"],
});

Configuration

The following environment variables are required in order for this module to function correctly to be defined in your .env:

NUXT_PUBLIC_CLERK_PUBLISHABLE_KEY=".."
NUXT_CLERK_SECRET_KEY="..."

# Optional: Enable this if you want to handle clerk webhooks
NUXT_CLERK_WEBHOOK_SIGNING_SECRET=".."

Vue Composables

NOTE: All of the composables and components are re-exported from vue-clerk. See project documentation for usage

Server Utils

The following helpers are auto-imported in your server/ directory.

Session Management

// Get the current clerk session if it exists, null otherwise
const clerkSession = await getClerkSession(event);

// Require a clerk session (send back 401 if no `user` session exists)
const clerkSession = await requireClerkSession(event);

Webhooks

To work with webhooks, first create the webhook on the clerk dashboard, and define a handler for it in your app like so:

Note: You must provide the CLERK_WEBHOOK_SIGNING_SECRET env (see above)

When defining a webhook in this way, you can assume that the webhook is valid as its signature is automatically verified.

// server/routes/clerk.post.ts
export default defineClerkWebhook('user.created', ({ payload }) => {
  console.log('payload', payload)
})


Development

# Install dependencies
pnpm install

# Generate type stubs
pnpm run dev:prepare

# Develop with the playground
pnpm run dev

# Build the playground
pnpm run dev:build

# Run ESLint
pnpm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release

Prior art and acknowledgments

FAQs

Package last updated on 03 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts