Skip to content

Commit

Permalink
added express rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSharma72 committed Oct 17, 2024
1 parent b6d3f29 commit c8ef193
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions backend/router/authRoute.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
const express = require("express");
const authRouter = express.Router();
const jwtAuth = require("../middleware/jwtAuth.js");
const rateLimit = require("express-rate-limit");

const {
signUp,
signIn,
forgotPassword,
resetPassword,
getUser,
logout
logout,
} = require("../controller/authController.js");

// Create a rate limiter for the /signin route
const signinLimiter = rateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes
max: 5, // Limit each IP to 5 requests per windowMs
message:
"Too many login attempts from this IP, please try again after 5 minutes",
});

// Apply routes
authRouter.post("/signup", signUp);
authRouter.post("/signin", signIn);

// Apply the rate limiter to the signin route
authRouter.post("/signin", signinLimiter, signIn);

authRouter.get("/user", jwtAuth, getUser);
authRouter.get("/logout", jwtAuth, logout);
Expand Down

0 comments on commit c8ef193

Please sign in to comment.