abhishek-akbari01
change password expose api
a08dcde
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;