0.0.5 • Published 5 months ago

elysia-clerk-test v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

elysia-clerk

Unofficial Clerk plugin for Elysia.js.

Install

bun install elysia-clerk

Usage

Retrieve your Backend API key from the API Keys screen in your Clerk dashboard and set it as an environment variable in a .env file:

CLERK_PUBLISHABLE_KEY=pk_*******
CLERK_SECRET_KEY=sk_******
import { Elysia } from 'elysia'
import { clerkPlugin } from 'elysia-clerk'

new Elysia()
  .use(clerkPlugin())
  .get('/private', async ({ clerk, store, set }) => {
    if (!store.auth?.userId) {
      set.status = 403
      return 'Unauthorized'
    }

    const user = await clerk.users.getUser(store.auth.userId)

    return { user }
  })
  .listen(3000)

Instead of using Clerk globally, you can use Clerk for a subset of routes via Elysia plugins:

import { Elysia } from 'elysia'
import { clerkPlugin } from 'elysia-clerk'

const privateRoutes = new Elysia({ prefix: '/api' })
  .use(clerkPlugin())
  .get('/user', async ({ clerk, store, set }) => {

    if (!store.auth?.userId) {
      set.status = 403
      return 'Unauthorized'
    }

    const user = await clerk.users.getUser(store.auth.userId)

    return { user }
  })

new Elysia()
  .use(privateRoutes)
  .get('/', () => 'Hello world!')
  .listen(3000)

License

MIT

0.0.5

5 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago