| 12345678910111213141516171819202122232425262728293031323334353637 |
- import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
- import { ErrorSchema } from '@d8d/shared-utils';
- import { authMiddleware } from '../middleware/index.mt';
- import { AuthContext } from '@d8d/shared-types';
- import { UserSchemaMt } from '@d8d/core-module-mt/user-module-mt';
- import { UserResponseSchema } from '../schemas/index.mt';
- 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;
|