Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added express rate limit #533

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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