fix middlewares

This commit is contained in:
Shane C 2024-08-27 12:12:40 -04:00
parent c973278b5a
commit 14c30beb49
Signed by: shane
GPG key ID: E46B5FEA35B22FF9

View file

@ -24,12 +24,8 @@ class CompleteReqBody {
code: string;
}
const beginRatelimiter = new RateLimiter('/login/begin', { limit: 10, timeframe: 300 });
const completeRatelimiter = new RateLimiter('/login/complete', { limit: 5, timeframe: 30 });
app.post('/login/begin',
(_args) => beginRatelimiter.middleware(),
requireAuth({ noAuthOnly: true }),
(_args) => requireAuth({ noAuthOnly: true }),
async (req: Request, res: Response) => {
if (typeof await isAuthenticated(req) == 'string') return res.status(403).send({ error: 'You are already authenticated' });
const body = req.body as BeginReqBody;
@ -40,8 +36,7 @@ app.post('/login/begin',
});
app.post('/login/complete',
(_args) => completeRatelimiter.middleware(),
requireAuth({ noAuthOnly: true }),
(_args) => requireAuth({ noAuthOnly: true }),
async (req: Request, res: Response) => {
const body = req.body as CompleteReqBody;
if ((!body.user || typeof body.user != 'string') ||