2
0

auth.schema.mt.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { z } from '@hono/zod-openapi';
  2. import { UserSchemaMt } from '@d8d/user-module-mt';
  3. export const LoginSchema = z.object({
  4. username: z.string().min(3).openapi({
  5. example: 'admin',
  6. description: '用户名'
  7. }),
  8. password: z.string().min(6).openapi({
  9. example: 'admin123',
  10. description: '密码'
  11. })
  12. });
  13. export const RegisterSchema = z.object({
  14. username: z.string().min(3).openapi({
  15. example: 'john_doe',
  16. description: '用户名'
  17. }),
  18. password: z.string().min(6).openapi({
  19. example: 'password123',
  20. description: '密码'
  21. }),
  22. email: z.string().email().openapi({
  23. example: 'john@example.com',
  24. description: '邮箱'
  25. }).optional()
  26. });
  27. export const MiniLoginSchema = z.object({
  28. code: z.string().openapi({
  29. example: '08123456789012345678901234567890',
  30. description: '小程序登录code'
  31. }),
  32. userInfo: z.object({
  33. nickName: z.string().optional(),
  34. avatarUrl: z.string().optional()
  35. }).optional()
  36. });
  37. export const UserResponseSchema = UserSchemaMt.omit({ password: true });
  38. export const TokenResponseSchema = z.object({
  39. token: z.string().openapi({
  40. example: 'jwt.token.here',
  41. description: 'JWT Token'
  42. }),
  43. user: UserResponseSchema
  44. });
  45. export const MiniLoginResponseSchema = z.object({
  46. token: z.string().openapi({
  47. example: 'jwt.token.here',
  48. description: 'JWT Token'
  49. }),
  50. user: z.object({
  51. id: z.number(),
  52. username: z.string(),
  53. nickname: z.string().nullable(),
  54. phone: z.string().nullable(),
  55. email: z.string().nullable(),
  56. avatarFileId: z.number().nullable(),
  57. registrationSource: z.string()
  58. }),
  59. isNewUser: z.boolean().openapi({
  60. example: true,
  61. description: '是否为新注册用户'
  62. })
  63. });
  64. export const SuccessSchema = z.object({
  65. message: z.string().openapi({ example: '登出成功' })
  66. });
  67. export const PhoneDecryptSchema = z.object({
  68. encryptedData: z.string().openapi({
  69. example: 'encrypted_phone_data_here',
  70. description: '微信小程序加密的手机号数据'
  71. }),
  72. iv: z.string().openapi({
  73. example: 'encryption_iv_here',
  74. description: '加密算法的初始向量'
  75. })
  76. });
  77. export const PhoneDecryptResponseSchema = z.object({
  78. phoneNumber: z.string().openapi({
  79. example: '13800138000',
  80. description: '解密后的手机号'
  81. }),
  82. user: z.object({
  83. id: z.number(),
  84. username: z.string(),
  85. nickname: z.string().nullable(),
  86. phone: z.string().nullable(),
  87. email: z.string().nullable(),
  88. avatarFileId: z.number().nullable(),
  89. registrationSource: z.string()
  90. })
  91. });