UNPKG

myex-cli

Version:

Opinionated Express.js framework with CLI tools

362 lines (354 loc) 11 kB
import express from 'express'; import { authController } from '../controllers/auth.controller.js'; const router = express.Router(); /** * @swagger * /api/auth/register: * post: * summary: Register a new user * tags: [Authentication] * requestBody: * required: true * content: * application/json: * schema: * type: object * required: * - name * - email * - password * properties: * name: * type: string * example: John Doe * email: * type: string * format: email * example: john@example.com * password: * type: string * format: password * example: Password123 * responses: * 201: * description: User registered successfully * content: * application/json: * schema: * type: object * properties: * status: * type: string * example: success * message: * type: string * example: User registered successfully * data: * type: object * properties: * user: * $ref: '#/components/schemas/User' * tokens: * type: object * properties: * accessToken: * type: string * example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... * refreshToken: * type: string * example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... * 400: * $ref: '#/components/responses/ValidationError' * 409: * description: User already exists * content: * application/json: * schema: * $ref: '#/components/schemas/Error' * example: * status: error * message: User with this email already exists * 500: * $ref: '#/components/responses/ServerError' */ router.post('/register', authController.register); /** * @swagger * /api/auth/login: * post: * summary: Authenticate a user * tags: [Authentication] * requestBody: * required: true * content: * application/json: * schema: * type: object * required: * - email * - password * properties: * email: * type: string * format: email * example: john@example.com * password: * type: string * format: password * example: Password123 * responses: * 200: * description: Login successful * content: * application/json: * schema: * type: object * properties: * status: * type: string * example: success * message: * type: string * example: Login successful * data: * type: object * properties: * user: * $ref: '#/components/schemas/User' * tokens: * type: object * properties: * accessToken: * type: string * example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... * refreshToken: * type: string * example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... * 400: * $ref: '#/components/responses/ValidationError' * 401: * description: Invalid credentials * content: * application/json: * schema: * $ref: '#/components/schemas/Error' * example: * status: error * message: Invalid email or password * 500: * $ref: '#/components/responses/ServerError' */ router.post('/login', authController.login); /** * @swagger * /api/auth/refresh-token: * post: * summary: Refresh access token * tags: [Authentication] * requestBody: * required: true * content: * application/json: * schema: * type: object * required: * - refreshToken * properties: * refreshToken: * type: string * example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... * responses: * 200: * description: Token refreshed successfully * content: * application/json: * schema: * type: object * properties: * status: * type: string * example: success * message: * type: string * example: Token refreshed successfully * data: * type: object * properties: * accessToken: * type: string * example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... * 400: * description: Refresh token is required * content: * application/json: * schema: * $ref: '#/components/schemas/Error' * example: * status: error * message: Refresh token is required * 403: * description: Invalid refresh token * content: * application/json: * schema: * $ref: '#/components/schemas/Error' * example: * status: error * message: Invalid refresh token * 500: * $ref: '#/components/responses/ServerError' */ router.post('/refresh-token', authController.refreshToken); /** * @swagger * /api/auth/logout: * post: * summary: Logout a user * tags: [Authentication] * requestBody: * required: true * content: * application/json: * schema: * type: object * required: * - refreshToken * properties: * refreshToken: * type: string * example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... * responses: * 200: * description: Logged out successfully * content: * application/json: * schema: * type: object * properties: * status: * type: string * example: success * message: * type: string * example: Logged out successfully * 400: * description: Refresh token is required * content: * application/json: * schema: * $ref: '#/components/schemas/Error' * example: * status: error * message: Refresh token is required * 500: * $ref: '#/components/responses/ServerError' */ router.post('/logout', authController.logout); /** * @swagger * /api/auth/forgot-password: * post: * summary: Request password reset * tags: [Authentication] * requestBody: * required: true * content: * application/json: * schema: * type: object * required: * - email * properties: * email: * type: string * format: email * example: john@example.com * responses: * 200: * description: Password reset instructions sent to email * content: * application/json: * schema: * type: object * properties: * status: * type: string * example: success * message: * type: string * example: Password reset instructions sent to email * 400: * description: Email is required * content: * application/json: * schema: * $ref: '#/components/schemas/Error' * example: * status: error * message: Email is required * 404: * $ref: '#/components/responses/NotFoundError' * 500: * $ref: '#/components/responses/ServerError' */ router.post('/forgot-password', authController.forgotPassword); /** * @swagger * /api/auth/reset-password: * post: * summary: Reset password with token * tags: [Authentication] * requestBody: * required: true * content: * application/json: * schema: * type: object * required: * - token * - newPassword * properties: * token: * type: string * example: 5f7d8d5b5c8d5a7d8d5b5c8d * newPassword: * type: string * format: password * example: NewPassword123 * responses: * 200: * description: Password reset successfully * content: * application/json: * schema: * type: object * properties: * status: * type: string * example: success * message: * type: string * example: Password reset successfully * 400: * description: Token and new password are required * content: * application/json: * schema: * $ref: '#/components/schemas/Error' * example: * status: error * message: Token and new password are required * 403: * description: Invalid or expired reset token * content: * application/json: * schema: * $ref: '#/components/schemas/Error' * example: * status: error * message: Invalid or expired reset token * 500: * $ref: '#/components/responses/ServerError' */ router.post('/reset-password', authController.resetPassword); export const authRoutes = router;