Build a Finance SaaS Platform -2 ( Hono )

Install Hono

1
npm i hono@latest

Install Hono plugin

1
npm i hono @hono/clerk-auth @clerk/backend

Add Route Logic

Add app/api/[[...route]]/route.ts:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { clerkMiddleware,getAuth } from '@hono/clerk-auth'
import { Hono } from 'hono'
import { handle } from 'hono/vercel'

export const runtime = 'edge'

const app = new Hono().basePath('/api')

app
.get('/hello',
clerkMiddleware(),
(c) => {
const auth = getAuth(c);

if (!auth?.userId) {
return c.json({ error: "Unauthorized" });
}

return c.json({
message: 'Hello Next.js!',
userId: auth.userId,
})
})

export const GET = handle(app)
export const POST = handle(app)

请我喝杯咖啡吧~

支付宝
微信