Spaces:
Runtime error
Runtime error
File size: 4,382 Bytes
7360e74 4e6da4f a08dcde 4e6da4f 250ca07 a08dcde 4e6da4f 7360e74 4e6da4f 250ca07 a08dcde 7360e74 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
import express from "express";
import { validateLogin } from "../validators/login.validator";
import { forgotPassword, login, resetPassword, changePassword } from "../controllers/auth.controller";
import { handleValidationErrors } from "../middlewares/handleValidatorError";
import { validateForgotPassword } from "../validators/forgotPassword.validator";
import { validateResetPassword } from "../validators/resetPassword.validator";
import { jwtMiddleware } from "../middlewares/authMiddleware";
const authRouter = express.Router();
/**
* @swagger
* components:
* schemas:
* jwt:
* type: object
* properties:
* token:
* type: string
* description: JWT token
* example:
* token : xyz
*
*/
/**
* @swagger
* /api/login:
* post:
* summary: User login
* tags: [Authentication]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* email:
* type: string
* password:
* type: string
* responses:
* 200:
* description: User authenticated successfully
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/jwt'
* 401:
* description: Invalid Credentials
* 403:
* description: Forbidden
* 500:
* description: Internal server error
*/
authRouter.post("/login", validateLogin, handleValidationErrors, login);
/**
* @swagger
* /api/auth/forgot-password:
* post:
* summary: Request password reset
* tags: [Authentication]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* email:
* type: string
* responses:
* 200:
* description: Password reset email sent successfully
* 404:
* description: User not found
* 500:
* description: Internal server error
*/
authRouter.post("/auth/forgot-password", validateForgotPassword, handleValidationErrors, forgotPassword);
/**
* @swagger
* /api/auth/reset-password:
* post:
* summary: Reset user password
* tags: [Authentication]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* token:
* type: string
* description: Reset token received via email
* newPassword:
* type: string
* description: New password to set
* responses:
* 200:
* description: Password reset successfully
* 400:
* description: Invalid or expired token
* 404:
* description: User not found
* 500:
* description: Internal server error
*/
authRouter.post("/auth/reset-password", validateResetPassword, handleValidationErrors, resetPassword);
/**
* @swagger
* /api/auth/change-password:
* post:
* summary: Change the current user's password
* tags: [Auth]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - currentPassword
* - newPassword
* - confirmPassword
* properties:
* currentPassword:
* type: string
* description: The current password of the user
* newPassword:
* type: string
* description: The new password to be set
* confirmPassword:
* type: string
* description: Confirmation of the new password
* responses:
* 200:
* description: Password changed successfully
* 400:
* description: Validation errors or incorrect current password
* 401:
* description: Unauthorized, user not authenticated
* 500:
* description: Internal server error
*/
authRouter.post('/auth/change-password', jwtMiddleware, changePassword);
export default authRouter;
|