Snai3i-LandingPage-FormBuilder / backend / src / routes / authRoutes.ts
authRoutes.ts
Raw
import { Router } from 'express';
import {
  deleteAdmin,
  getAllUsers,
  getProfile,
  loginAdmin,
  logoutAdmin,
  registerAdmin,
  resetPassword,
  updateProfile,
} from '../controllers/authController';
import { Schemas, ValidateBodySchema } from '../middlewares/validateSchemaMiddleware';
import {checkSuperAdmin, protect} from '../middlewares/authMiddleware';


const authRouter = Router();

authRouter.post('/register', protect, checkSuperAdmin, ValidateBodySchema(Schemas.user.register), registerAdmin);

authRouter.post('/login', ValidateBodySchema(Schemas.user.login), loginAdmin);

authRouter.post('/logout', logoutAdmin);

authRouter.route('/profile').get(protect, getProfile).put(protect, ValidateBodySchema(Schemas.user.update), updateProfile);

authRouter.route('/password').put(protect, checkSuperAdmin, ValidateBodySchema(Schemas.user.updatePassword), resetPassword);

authRouter.route('/delete').delete(protect, checkSuperAdmin, ValidateBodySchema(Schemas.user.delete), deleteAdmin);

authRouter.route('/users').get(protect, checkSuperAdmin, getAllUsers);


export default authRouter;