https://github.com/wobsoriano/elysia-clerk
Unofficial Clerk plugin for Elysia.js.
https://github.com/wobsoriano/elysia-clerk
auth bun
Last synced: about 1 month ago
JSON representation
Unofficial Clerk plugin for Elysia.js.
- Host: GitHub
- URL: https://github.com/wobsoriano/elysia-clerk
- Owner: wobsoriano
- License: mit
- Created: 2023-08-07T00:40:18.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-28T16:46:39.000Z (about 2 months ago)
- Last Synced: 2025-03-28T21:04:01.356Z (about 2 months ago)
- Topics: auth, bun
- Language: TypeScript
- Homepage:
- Size: 619 KB
- Stars: 78
- Watchers: 3
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-elysia - Clerk - Unofficial Clerk plugin. (Plugins)
README
# elysia-clerk
Elysia plugin to integrate with [Clerk](https://clerk.com/).
> [!NOTE]
> This unofficial package isn't connected to Clerk.com. It's a project designed to smoothly incorporate Clerk features to your Elysia applications.## Install
```bash
bun add elysia-clerk
```## Usage
Retrieve your Backend API key from the [API Keys](https://dashboard.clerk.com/last-active?path=api-keys) screen in your Clerk dashboard and set it as an environment variable in a .env file:
```sh
CLERK_PUBLISHABLE_KEY=pk_*******
CLERK_SECRET_KEY=sk_******
```Configure `clerkPlugin` in your Elysia application
```ts
import { Elysia } from 'elysia'
import { clerkPlugin } from 'elysia-clerk'new Elysia()
.use(clerkPlugin())
.get('/private', async (ctx) => {
const auth = ctx.auth()/**
* Access the auth state in the context.
* See the AuthObject here https://clerk.com/docs/references/nextjs/auth-object#auth-object
*/
if (!auth?.userId) {
return ctx.error(401)
}/**
* For other resource operations, you can use the clerk client from the context.
* See what other utilities Clerk exposes here https://clerk.com/docs/references/backend/overview
*/
const user = await ctx.clerk.users.getUser(auth.userId)return { user }
})
.listen(3000)
```To see the available options you can pass to the `clerkPlugin` function, see [`AuthenticateRequestOptions`](https://clerk.com/docs/references/backend/authenticate-request#authenticate-request-options).
## License
MIT