@@ -2,6 +2,18 @@ import { Router } from "express";
22import { AuthController } from "./auth.controller.js" ;
33import { AuthService } from "./auth.service.js" ;
44import { authMiddleware } from "../../middleware/auth.middleware.js" ;
5+ import rateLimit from "express-rate-limit" ;
6+
7+ const createOtpRateLimit = ( max : number , message : string ) => rateLimit ( {
8+ windowMs : 15 * 60 * 1000 ,
9+ max,
10+ message : { message } ,
11+ standardHeaders : true ,
12+ legacyHeaders : false ,
13+ } ) ;
14+
15+ const verifyEmailRateLimit = createOtpRateLimit ( 5 , "Too many attempts, please try again after 15 minutes" ) ;
16+ const resendOtpRateLimit = createOtpRateLimit ( 3 , "Too many resend attempts, please try again after 15 minutes" ) ;
517
618const authService = new AuthService ( ) ;
719const authController = new AuthController ( authService ) ;
@@ -11,8 +23,8 @@ export const authRouter = Router();
1123authRouter . post ( "/register" , ( req , res ) => authController . register ( req , res ) ) ;
1224authRouter . post ( "/login" , ( req , res ) => authController . login ( req , res ) ) ;
1325authRouter . post ( "/google" , ( req , res ) => authController . googleAuth ( req , res ) ) ;
14- authRouter . post ( "/verify-email" , ( req , res ) => authController . verifyEmail ( req , res ) ) ;
15- authRouter . post ( "/resend-otp" , ( req , res ) => authController . resendOtp ( req , res ) ) ;
26+ authRouter . post ( "/verify-email" , verifyEmailRateLimit , ( req , res ) => authController . verifyEmail ( req , res ) ) ;
27+ authRouter . post ( "/resend-otp" , resendOtpRateLimit , ( req , res ) => authController . resendOtp ( req , res ) ) ;
1628authRouter . post ( "/forgot-password" , ( req , res ) => authController . forgotPassword ( req , res ) ) ;
1729authRouter . post ( "/reset-password" , ( req , res ) => authController . resetPassword ( req , res ) ) ;
1830authRouter . post ( "/logout" , ( req , res ) => authController . logout ( req , res ) ) ;
0 commit comments