- Added `auth.ts` for JWT authentication middleware. - Created `auth` route to handle authentication and token verification. - Integrated authentication middleware into `media.ts` for protected routes. - Updated `main.ts` to register the new authentication route.
20 lines
413 B
TypeScript
20 lines
413 B
TypeScript
import { Hono } from 'hono'
|
|
import type { JwtVariables } from 'hono/jwt'
|
|
import { authMiddleware } from '../auth.ts'
|
|
|
|
const auth = new Hono<{ Variables: JwtVariables }>()
|
|
|
|
auth.use('/*', authMiddleware)
|
|
|
|
auth.get('/verify', (c) => {
|
|
const payload = c.get('jwtPayload')
|
|
return c.json({
|
|
code: 0,
|
|
data: {
|
|
username: payload.username,
|
|
},
|
|
message: '认证成功',
|
|
})
|
|
})
|
|
|
|
export default auth
|