20 lines
607 B
TypeScript
20 lines
607 B
TypeScript
import rateLimit from "express-rate-limit";
|
|
import type { Request } from "express";
|
|
|
|
export const loginRateLimit = rateLimit({
|
|
windowMs: 60 * 1000,
|
|
limit: 10,
|
|
standardHeaders: "draft-7",
|
|
legacyHeaders: false,
|
|
message: { error: "Too many login attempts, please try again later." },
|
|
});
|
|
|
|
export const passwordRateLimit = rateLimit({
|
|
windowMs: 60 * 1000,
|
|
limit: 5,
|
|
standardHeaders: "draft-7",
|
|
legacyHeaders: false,
|
|
keyGenerator: (req: Request): string => String(req.session.user?.sub ?? req.ip ?? "unknown"),
|
|
message: { error: "Too many password attempts, please try again later." },
|
|
});
|