wobsoriano / vue-clerk

Community Clerk Vue SDK.
https://vue-clerk.com
MIT License
157 stars 14 forks source link

feat: Add experimental custom server middleware #173

Closed wobsoriano closed 4 weeks ago

wobsoriano commented 1 month ago

Due to a current Nuxt limitation, modules cannot run their middlewares before scanned middlewares (see issue #26012).

This PR adds option to skip adding of the custom Clerk server middleware to be handled in userland and be able to do custom logic.

Example usage:

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['vue-clerk/nuxt'],
  clerk: {
    __experimental_skipServerMiddleware: true
  },
})
// server/middleware/clerk.ts
import { clerkMiddleware } from 'vue-clerk/server'

export default clerkMiddleware((event) => {
  const { auth } = event.context

  if (!auth.userId && event.path.startsWith('/api')) {
    throw createError({
      statusCode: 401,
      message: 'Unauthorized'
    })
  }
})
changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: bde201a9b07bf287f2e012bcc30201e082f2598d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | --------- | ----- | | vue-clerk | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vue-clerk ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 27, 2024 3:46pm
pkg-pr-new[bot] commented 1 month ago

Open in Stackblitz

pnpm add https://pkg.pr.new/vue-clerk@173

commit: bde201a