Skip to content

Commit

Permalink
added rate limit middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSharma72 committed Oct 17, 2024
1 parent b6d3f29 commit af80ab2
Show file tree
Hide file tree
Showing 532 changed files with 68,831 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
/node_modules
.env
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
16 changes: 16 additions & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/mime.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/mime.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit af80ab2

Please sign in to comment.