-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add authRateLimitCheck middleware #23
- Loading branch information
1 parent
3dff090
commit c7f6fbc
Showing
3 changed files
with
26 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Temp } from "../models/Temp.js"; | ||
|
||
export default async function authRateLimitCheck(req, res, next){ | ||
const ip = (req.headers['x-forwarded-for'] || '').split(',').pop().trim() || | ||
req.connection.remoteAddress || | ||
req.socket.remoteAddress || | ||
req.connection.socket.remoteAddress; | ||
|
||
const tempIP = await Temp.exists({'value.ip': ip}); | ||
|
||
if(!tempIP){ | ||
console.log('here'); | ||
next(); | ||
} else { | ||
return res.status(429).json({ message: "We have sended an email with verification to you" }); | ||
} | ||
} |
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