Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .changeset/clerk-hono-initial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
'@clerk/hono': minor
---

Initial release of `@clerk/hono` - the official Clerk SDK for Hono.

This package provides:
- `clerkMiddleware()` - Middleware to authenticate requests and attach auth data to Hono context
- `getAuth(c)` - Helper to retrieve auth data from Hono context
- `verifyWebhook(c)` - Webhook verification via `@clerk/hono/webhooks`

**Usage:**

```typescript
import { Hono } from 'hono';
import { clerkMiddleware, getAuth } from '@clerk/hono';

const app = new Hono();

app.use('*', clerkMiddleware());

app.get('/protected', (c) => {
const { userId } = getAuth(c);
if (!userId) {
return c.json({ error: 'Unauthorized' }, 401);
}
return c.json({ userId });
});
```

Based on the community `@hono/clerk-auth` package. Thank you to Vaggelis Yfantis for the original implementation!
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}
],
"commit": false,
"ignore": ["@clerk/hono"],
"fixed": [],
"linked": [],
"access": "public",
Expand Down
154 changes: 154 additions & 0 deletions packages/hono/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<p align="center">
<a href="https://clerk.com?utm_source=github&utm_medium=clerk_hono" target="_blank" rel="noopener noreferrer">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://images.clerk.com/static/logo-dark-mode-400x400.png">
<img src="https://images.clerk.com/static/logo-light-mode-400x400.png" height="64">
</picture>
</a>
<br />
</p>

# @clerk/hono

<div align="center">

[![Chat on Discord](https://img.shields.io/discord/856971667393609759.svg?logo=discord)](https://clerk.com/discord)
[![Clerk documentation](https://img.shields.io/badge/documentation-clerk-green.svg)](https://clerk.com/docs?utm_source=github&utm_medium=clerk_hono)
[![Follow on Twitter](https://img.shields.io/twitter/follow/ClerkDev?style=social)](https://twitter.com/intent/follow?screen_name=ClerkDev)

[Changelog](https://github.com/clerk/javascript/blob/main/packages/hono/CHANGELOG.md)
·
[Report a Bug](https://github.com/clerk/javascript/issues/new?assignees=&labels=needs-triage&projects=&template=BUG_REPORT.yml)
·
[Request a Feature](https://feedback.clerk.com/roadmap)
·
[Get help](https://clerk.com/contact/support?utm_source=github&utm_medium=clerk_hono)

</div>

## Getting Started

[Clerk](https://clerk.com/?utm_source=github&utm_medium=clerk_hono) is the easiest way to add authentication and user management to your Hono application. Add sign up, sign in, and profile management to your application in minutes.

### Prerequisites

- Hono 4+
- Node.js 20+

Comment on lines +33 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add a compatibility matrix for supported versions.

The README lists prerequisites but does not include the required compatibility matrix.

Suggested update
 ### Prerequisites

 - Hono 4+
 - Node.js 20+
+
+### Compatibility Matrix
+| Dependency | Supported versions |
+|---|---|
+| Hono | >= 4 |
+| Node.js | >= 20 |

As per coding guidelines, "packages/*/README.md: Maintain compatibility matrices for supported versions".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### Prerequisites
- Hono 4+
- Node.js 20+
### Prerequisites
- Hono 4+
- Node.js 20+
### Compatibility Matrix
| Dependency | Supported versions |
|---|---|
| Hono | >= 4 |
| Node.js | >= 20 |
🤖 Prompt for AI Agents
In `@packages/hono/README.md` around lines 33 - 37, Update the "Prerequisites"
section to include a compatibility matrix: under the existing "Prerequisites"
heading (currently listing "Hono 4+" and "Node.js 20+"), add a short table or
bullet list that explicitly maps supported Hono versions to supported Node.js
versions (e.g., Hono 4.x → Node 20+, Hono 3.x → Node 18 LTS if still supported),
indicate which module formats (ESM/CJS) are supported, and note the minimum
tested CI matrix; ensure the matrix mentions the minimum supported versions and
the CI-tested combinations so consumers can see exact compatibility.

### Installation

```sh
npm install @clerk/hono
```

### Configuration

Set your Clerk API keys as environment variables:

```sh
CLERK_SECRET_KEY=sk_****
CLERK_PUBLISHABLE_KEY=pk_****
```

### Usage

```typescript
import { Hono } from 'hono';
import { clerkMiddleware, getAuth } from '@clerk/hono';

const app = new Hono();

// Apply Clerk middleware to all routes
app.use('*', clerkMiddleware());

// Public route
app.get('/', c => {
return c.json({ message: 'Hello!' });
});

// Protected route
app.get('/protected', c => {
const { userId } = getAuth(c);

if (!userId) {
return c.json({ error: 'Unauthorized' }, 401);
}

return c.json({ message: 'Hello authenticated user!', userId });
});

export default app;
```

### Accessing the Clerk Client

You can access the Clerk Backend API client directly from the context:

```typescript
app.get('/user/:id', async c => {
const clerkClient = c.get('clerk');
const user = await clerkClient.users.getUser(c.req.param('id'));
return c.json({ user });
});
```

### Using `acceptsToken` for Machine Auth

```typescript
app.get('/api', c => {
const auth = getAuth(c, { acceptsToken: 'api_key' });

if (!auth.userId) {
return c.json({ error: 'Unauthorized' }, 401);
}

return c.json({ message: 'API access granted' });
});
```

### Webhook Verification

```typescript
import { Hono } from 'hono';
import { verifyWebhook } from '@clerk/hono/webhooks';

const app = new Hono();

app.post('/webhooks/clerk', async c => {
const evt = await verifyWebhook(c);

switch (evt.type) {
case 'user.created':
console.log('User created:', evt.data.id);
break;
// Handle other event types...
}

return c.json({ received: true });
});
```

## Support

You can get in touch with us in any of the following ways:

- Join our official community [Discord server](https://clerk.com/discord)
- On [our support page](https://clerk.com/contact/support?utm_source=github&utm_medium=clerk_hono)

## Contributing

We're open to all community contributions! If you'd like to contribute in any way, please read [our contribution guidelines](https://github.com/clerk/javascript/blob/main/docs/CONTRIBUTING.md) and [code of conduct](https://github.com/clerk/javascript/blob/main/docs/CODE_OF_CONDUCT.md).

## Security

`@clerk/hono` follows good practices of security, but 100% security cannot be assured.

`@clerk/hono` is provided **"as is"** without any **warranty**. Use at your own risk.

_For more information and to report security issues, please refer to our [security documentation](https://github.com/clerk/javascript/blob/main/docs/SECURITY.md)._

## License

This project is licensed under the **MIT license**.

See [LICENSE](https://github.com/clerk/javascript/blob/main/packages/hono/LICENSE) for more information.
91 changes: 91 additions & 0 deletions packages/hono/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"name": "@clerk/hono",
"version": "0.0.1",
"description": "Clerk SDK for Hono",
"keywords": [
"auth",
"authentication",
"passwordless",
"session",
"jwt",
"hono",
"clerk"
],
"homepage": "https://clerk.com/",
"bugs": {
"url": "https://github.com/clerk/javascript/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/clerk/javascript.git",
"directory": "packages/hono"
},
"license": "MIT",
"author": "Clerk",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./webhooks": {
"import": {
"types": "./dist/webhooks.d.mts",
"default": "./dist/webhooks.mjs"
},
"require": {
"types": "./dist/webhooks.d.ts",
"default": "./dist/webhooks.js"
}
},
"./types": {
"import": {
"types": "./dist/types.d.mts"
},
"require": {
"types": "./dist/types.d.ts"
}
}
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsup --env.NODE_ENV production",
"clean": "rimraf ./dist",
"dev": "tsup --watch",
"format": "node ../../scripts/format-package.mjs",
"format:check": "node ../../scripts/format-package.mjs --check",
"lint": "eslint src",
"lint:attw": "attw --pack . --profile node16",
"lint:publint": "publint",
"publish:local": "pnpm yalc push --replace --sig",
"test": "vitest run",
"test:watch": "vitest watch"
},
"dependencies": {
"@clerk/backend": "workspace:^",
"@clerk/shared": "workspace:^"
},
"devDependencies": {
"hono": "^4.7.4"
},
"peerDependencies": {
"hono": ">=4"
},
"engines": {
"node": ">=20"
},
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`@clerk/hono public exports > should not include a breaking change 1`] = `
[
"clerkMiddleware",
"getAuth",
]
`;
Loading
Loading