-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1703 from AyushSharma72/ratelimit
added rate limit api to login api
- Loading branch information
Showing
4 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.env | ||
.env | ||
/node_modules |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
const express = require('express'); | ||
const { signup, login, logout, verifyToken } = require('../controllers/authController'); | ||
const express = require("express"); | ||
const rateLimit = require("express-rate-limit"); | ||
const { | ||
signup, | ||
login, | ||
logout, | ||
verifyToken, | ||
} = require("../controllers/authController"); | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/signup', signup); | ||
router.post('/login', login); | ||
router.post('/logout', logout); | ||
router.get('/verify', verifyToken); // New verification route | ||
// Set up rate limiter for the login route | ||
const loginRateLimiter = rateLimit({ | ||
windowMs: 5 * 60 * 1000, // 5 minutes | ||
max: 5, | ||
message: "Too many login attempts. Please try again in 5 minutes.", | ||
standardHeaders: true, | ||
legacyHeaders: false, | ||
}); | ||
|
||
router.post("/signup", signup); | ||
router.post("/login", loginRateLimiter, login); // Apply the limiter here | ||
router.post("/logout", logout); | ||
router.get("/verify", verifyToken); | ||
|
||
module.exports = router; |