0.2.41 • Published 2 years ago
h3-clerk-test v0.2.41
h3-clerk
Unofficial Clerk middleware for H3.
Check here for a demo with Nuxt.
Getting Started
To use this middleware you should first create a Clerk application and retrieve a Secret Key and a Publishable Key for your application (see here) to be used as environment variables CLERK_PUBLISHABLE_KEY & CLERK_SECRET_KEY.
Installation
npm install h3-clerkUsage
import { createApp, createError, eventHandler } from 'h3'
import { clerkClient, getAuth, withClerkMiddleware } from 'h3-clerk'
const app = createApp()
// For all routes
app.use(withClerkMiddleware())
app.use('/protected-endpoint', async (event) => {
const { userId } = getAuth(event)
if (!userId)
throw createError({ statusCode: 403 })
const user = await clerkClient.users.getUser(userId)
return { user }
})
// For a single route
app.use(
'/protected-endpoint',
eventHandler({
onRequest: [withClerkMiddleware()],
handler: async (event) => {
const { userId } = getAuth(event)
if (!userId)
throw createError({ statusCode: 403 })
const user = await clerkClient.users.getUser(userId)
return { user }
}
})
)TypeScript Shim
import type { SignedInAuthObject, SignedOutAuthObject } from '@clerk/backend/internal'
declare module 'h3' {
interface H3EventContext {
auth: SignedInAuthObject | SignedOutAuthObject
}
}License
MIT
0.2.41
2 years ago
0.2.40
2 years ago
0.2.27
2 years ago
0.2.26
2 years ago
0.2.25
2 years ago
0.2.24
2 years ago
0.2.23
2 years ago
0.2.22
2 years ago
0.2.21
2 years ago
0.2.20
2 years ago
0.2.19
2 years ago
0.2.18
2 years ago
0.2.39
2 years ago
0.2.17
2 years ago
0.2.30
2 years ago
0.2.38
2 years ago
0.2.16
2 years ago
0.2.37
2 years ago
0.2.15
2 years ago
0.2.36
2 years ago
0.2.14
2 years ago
0.2.35
2 years ago
0.2.13
2 years ago
0.2.34
2 years ago
0.2.12
2 years ago
0.2.33
2 years ago
0.2.32
2 years ago
0.2.10
2 years ago
0.2.29
2 years ago
0.2.28
2 years ago
0.2.7
2 years ago
0.2.9
2 years ago
0.2.8
2 years ago
0.2.6
2 years ago
0.2.3
2 years ago
0.2.2
2 years ago
0.2.5
2 years ago
0.2.4
2 years ago
0.1.0
3 years ago