|
| 1 | +import { z } from "zod"; |
| 2 | +import { |
| 3 | + authResponseSchema, |
| 4 | + tokenPairSchema, |
| 5 | + userResponseSchema |
| 6 | +} from "../../schemas/auth"; |
| 7 | +import { errorResponseSchema } from "../../schemas/common"; |
| 8 | + |
| 9 | +export const registerBodySchema = z.object({ |
| 10 | + email: z.string().email(), |
| 11 | + password: z.string().min(8), |
| 12 | + name: z.string().trim().min(1).max(100).optional() |
| 13 | +}); |
| 14 | + |
| 15 | +export const loginBodySchema = z.object({ |
| 16 | + email: z.string().email(), |
| 17 | + password: z.string().min(1) |
| 18 | +}); |
| 19 | + |
| 20 | +export const refreshBodySchema = z.object({ |
| 21 | + refreshToken: z.string().min(1) |
| 22 | +}); |
| 23 | + |
1 | 24 | export const registerSchema = { |
2 | 25 | tags: ["Authentication"], |
3 | 26 | summary: "Register a user", |
4 | | - description: "Creates a user account and returns access and refresh tokens.", |
5 | | - body: { |
6 | | - type: "object", |
7 | | - additionalProperties: false, |
8 | | - required: ["email", "password"], |
9 | | - properties: { |
10 | | - email: { type: "string", format: "email", examples: ["user@example.com"] }, |
11 | | - password: { type: "string", minLength: 8, examples: ["strong-password"] }, |
12 | | - name: { type: "string", minLength: 1, maxLength: 100, examples: ["Example User"] } |
13 | | - } |
14 | | - }, |
| 27 | + description: |
| 28 | + "Creates a user account and returns access and refresh tokens.", |
| 29 | + body: registerBodySchema, |
15 | 30 | response: { |
16 | | - 201: { $ref: "AuthResponse#" }, |
17 | | - 409: { $ref: "ErrorResponse#" } |
| 31 | + 201: authResponseSchema, |
| 32 | + 409: errorResponseSchema |
18 | 33 | } |
19 | | -} as const; |
| 34 | +}; |
20 | 35 |
|
21 | 36 | export const loginSchema = { |
22 | 37 | tags: ["Authentication"], |
23 | 38 | summary: "Log in a user", |
24 | | - description: "Authenticates credentials and returns access and refresh tokens.", |
25 | | - body: { |
26 | | - type: "object", |
27 | | - additionalProperties: false, |
28 | | - required: ["email", "password"], |
29 | | - properties: { |
30 | | - email: { type: "string", format: "email" }, |
31 | | - password: { type: "string", minLength: 1 } |
32 | | - } |
33 | | - }, |
| 39 | + description: |
| 40 | + "Authenticates credentials and returns access and refresh tokens.", |
| 41 | + body: loginBodySchema, |
34 | 42 | response: { |
35 | | - 200: { $ref: "AuthResponse#" }, |
36 | | - 401: { $ref: "ErrorResponse#" } |
| 43 | + 200: authResponseSchema, |
| 44 | + 401: errorResponseSchema |
37 | 45 | } |
38 | | -} as const; |
| 46 | +}; |
39 | 47 |
|
40 | 48 | export const refreshSchema = { |
41 | 49 | tags: ["Authentication"], |
42 | 50 | summary: "Refresh authentication tokens", |
43 | | - description: "Rotates a valid refresh token and returns a new token pair.", |
44 | | - body: { |
45 | | - type: "object", |
46 | | - additionalProperties: false, |
47 | | - required: ["refreshToken"], |
48 | | - properties: { refreshToken: { type: "string", minLength: 1 } } |
49 | | - }, |
| 51 | + description: |
| 52 | + "Rotates a valid refresh token and returns a new token pair.", |
| 53 | + body: refreshBodySchema, |
50 | 54 | response: { |
51 | | - 200: { $ref: "TokenPair#" }, |
52 | | - 401: { $ref: "ErrorResponse#" } |
| 55 | + 200: tokenPairSchema, |
| 56 | + 401: errorResponseSchema |
53 | 57 | } |
54 | | -} as const; |
| 58 | +}; |
55 | 59 |
|
56 | 60 | export const logoutSchema = { |
57 | 61 | tags: ["Authentication"], |
58 | 62 | summary: "Log out a user", |
59 | | - description: "Revokes the supplied refresh token.", |
60 | | - body: { |
61 | | - type: "object", |
62 | | - additionalProperties: false, |
63 | | - required: ["refreshToken"], |
64 | | - properties: { refreshToken: { type: "string", minLength: 1 } } |
65 | | - }, |
66 | | - response: { 204: { type: "null" } } |
67 | | -} as const; |
| 63 | + description: |
| 64 | + "Revokes the supplied refresh token.", |
| 65 | + body: refreshBodySchema, |
| 66 | + response: { |
| 67 | + 204: z.null() |
| 68 | + } |
| 69 | +}; |
68 | 70 |
|
69 | 71 | export const meSchema = { |
70 | 72 | tags: ["Authentication"], |
71 | 73 | summary: "Get the authenticated user", |
72 | | - description: "Returns the currently authenticated user's public profile.", |
73 | | - security: [{ bearerAuth: [] }], |
| 74 | + description: |
| 75 | + "Returns the currently authenticated user's public profile.", |
| 76 | + security: [ |
| 77 | + { |
| 78 | + bearerAuth: [] |
| 79 | + } |
| 80 | + ], |
74 | 81 | response: { |
75 | | - 200: { $ref: "UserResponse#" }, |
76 | | - 401: { $ref: "ErrorResponse#" } |
| 82 | + 200: userResponseSchema, |
| 83 | + 401: errorResponseSchema |
77 | 84 | } |
78 | | -} as const; |
| 85 | +}; |
0 commit comments