| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { createRoute, OpenAPIHono } from '@hono/zod-openapi'
- import { ErrorSchema } from '@/server/utils/errorHandler'
- import { authMiddleware } from '@/server/middleware/auth.middleware'
- import { AuthContext } from '@/server/types/context'
- import { UserSchema } from '@/server/modules/users/user.schema'
- const UserResponseSchema = UserSchema.omit({
- password: true
- });
- const routeDef = createRoute({
- method: 'get',
- path: '/me',
- middleware: authMiddleware,
- responses: {
- 200: {
- description: '获取当前用户信息成功',
- content: {
- 'application/json': {
- schema: UserResponseSchema
- }
- }
- },
- 401: {
- description: '未授权',
- content: {
- 'application/json': {
- schema: ErrorSchema
- }
- }
- }
- }
- })
- const app = new OpenAPIHono<AuthContext>().openapi(routeDef, (c) => {
- const user = c.get('user')
- return c.json(user, 200)
- })
- export default app
|