Skip to content

Commit 4d4cfd6

Browse files
authored
feat(hono): add hono integration package (@aura-stack/hono) (#139)
* feat(hono): add hono integration package (@aura-stack/hono) * chore: sync dependencies and apply coderabbit
1 parent b49ff7e commit 4d4cfd6

32 files changed

Lines changed: 1108 additions & 172 deletions

apps/express/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
"dependencies": {
1616
"@aura-stack/auth": "workspace:*",
1717
"@aura-stack/express": "workspace:*",
18-
"express": "^4.18.2"
18+
"express": "catalog:express"
1919
},
2020
"devDependencies": {
2121
"@aura-stack/tsconfig": "workspace:*",
22-
"@types/express": "^4.17.21",
23-
"@types/node": "^20.10.6",
22+
"@types/express": "catalog:express",
23+
"@types/node": "catalog:node",
2424
"tsx": "^4.7.0",
2525
"typescript": "^5.3.3"
2626
},

apps/hono/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<h1>Aura Auth + Hono</h1>
44

5-
**Demonstration app**
5+
**Integration Example App**
66

77
[Official Docs](https://aura-stack-auth.vercel.app/docs) · [Hono](https://hono.dev/)
88

@@ -12,7 +12,15 @@
1212

1313
## Overview
1414

15-
This project demonstrates Aura Auth authentication using [OAuth 2.0 providers](https://aura-stack-auth.vercel.app/docs/) in a [Hono](https://hono.dev/) application.
15+
This project demonstrates **Aura Auth** authentication using [OAuth 2.0 providers](https://aura-stack-auth.vercel.app/docs/) in a [Hono](https://hono.dev/) application.
16+
17+
This integration utilizes the dedicated [`@aura-stack/hono`](../../packages/hono) package, which provides standard middlewares and first-class TypeScript support for Hono applications.
18+
19+
## Features Demo
20+
21+
- **Type-safe Middleware**: Uses `withAuth` to protect routes and infer session shapes.
22+
- **Unified Auth Handler**: Reuses framework-agnostic core logic via `toHandler`.
23+
- **Global Context**: Demonstrates how `ctx.get("session")` is automatically populated and typed.
1624

1725
## Getting Started
1826

apps/hono/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
"format:check": "oxfmt --check"
1010
},
1111
"dependencies": {
12-
"@aura-stack/auth": "workspace:*",
13-
"@aura-stack/jose": "workspace:*",
14-
"hono": "^4.12.8"
12+
"@aura-stack/hono": "workspace:*",
13+
"hono": "catalog:hono"
1514
},
1615
"devDependencies": {
1716
"@aura-stack/tsconfig": "workspace:*",
18-
"@types/bun": "^1.3.9"
17+
"@types/bun": "catalog:bun"
1918
}
2019
}

apps/hono/src/auth.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

apps/hono/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { Hono } from "hono"
2-
import { toHonoHandler } from "./lib/handler"
3-
import { type AuthVariables, withAuth } from "./middleware/with-auth"
2+
import { toHandler, withAuth } from "@/lib/auth"
43

5-
const app = new Hono<{ Variables: AuthVariables }>()
4+
const app = new Hono()
65

76
app.get("/", (ctx) => {
87
return ctx.text("Welcome to the Aura Auth Hono App!")
98
})
109

11-
app.all("/api/auth/*", toHonoHandler)
10+
app.all("/api/auth/*", toHandler)
1211

1312
app.get("/api/protected", withAuth, (ctx) => {
1413
const session = ctx.get("session")
14+
if (!session) {
15+
return ctx.json({ message: "Unauthorized" }, 401)
16+
}
17+
1518
return ctx.json({
1619
message: "You have access to this protected resource.",
1720
session,

apps/hono/src/lib/auth.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createAuth } from "@aura-stack/hono"
2+
3+
export const auth = createAuth({
4+
oauth: ["github"],
5+
basePath: "/api/auth",
6+
})
7+
8+
export const { jose, api, toHandler, withAuth } = auth

apps/hono/src/lib/handler.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

apps/hono/src/middleware/with-auth.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

apps/hono/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"extends": "@aura-stack/tsconfig/bun.json",
33
"compilerOptions": {
4-
"jsxImportSource": "hono/jsx"
4+
"jsxImportSource": "hono/jsx",
5+
"paths": {
6+
"@/*": ["./src/*"]
7+
}
58
},
69
"include": ["src"],
710
"exclude": ["dist", "node_modules"]

0 commit comments

Comments
 (0)