me.route.mt.ts 929 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
  2. import { ErrorSchema } from '@d8d/shared-utils';
  3. import { authMiddleware } from '../middleware/index.mt';
  4. import { AuthContext } from '@d8d/shared-types';
  5. import { UserSchemaMt } from '@d8d/core-module-mt/user-module-mt';
  6. import { UserResponseSchema } from '../schemas/index.mt';
  7. const routeDef = createRoute({
  8. method: 'get',
  9. path: '/me',
  10. middleware: authMiddleware,
  11. responses: {
  12. 200: {
  13. description: '获取当前用户信息成功',
  14. content: {
  15. 'application/json': {
  16. schema: UserResponseSchema
  17. }
  18. }
  19. },
  20. 401: {
  21. description: '未授权',
  22. content: {
  23. 'application/json': {
  24. schema: ErrorSchema
  25. }
  26. }
  27. }
  28. }
  29. });
  30. const app = new OpenAPIHono<AuthContext>().openapi(routeDef, (c) => {
  31. const user = c.get('user');
  32. return c.json(user, 200);
  33. });
  34. export default app;