0.2.41 • Published 12 months 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-clerk
Usage
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
12 months ago
0.2.40
12 months ago
0.2.27
12 months ago
0.2.26
12 months ago
0.2.25
12 months ago
0.2.24
12 months ago
0.2.23
1 year ago
0.2.22
1 year ago
0.2.21
1 year ago
0.2.20
1 year ago
0.2.19
1 year ago
0.2.18
1 year ago
0.2.39
12 months ago
0.2.17
1 year ago
0.2.30
12 months ago
0.2.38
12 months ago
0.2.16
1 year ago
0.2.37
12 months ago
0.2.15
1 year ago
0.2.36
12 months ago
0.2.14
1 year ago
0.2.35
12 months ago
0.2.13
1 year ago
0.2.34
12 months ago
0.2.12
1 year ago
0.2.33
12 months ago
0.2.32
12 months ago
0.2.10
1 year ago
0.2.29
12 months ago
0.2.28
12 months ago
0.2.7
1 year ago
0.2.9
1 year ago
0.2.8
1 year 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
2 years ago