We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents dc77b57 + 6c8c2bf commit 812f789Copy full SHA for 812f789
1 file changed
src/server/utils/ratelimit.ts
@@ -35,7 +35,20 @@ export async function checkLoginAttempt(ip: string): Promise<boolean> {
35
36
export async function rollbackLoginAttempt(ip: string): Promise<void> {
37
const redis = getClient();
38
- await redis.decr(`rate_limit:login:${ip}`);
+ const key = `rate_limit:login:${ip}`;
39
+
40
+ const results = await redis
41
+ .multi()
42
+ .decr(key)
43
+ .expire(key, WINDOW_SECONDS)
44
+ .exec();
45
46
+ const newCount =
47
+ results && results[0] && Array.isArray(results[0]) ? (results[0][1] as number) : 0;
48
49
+ if (newCount <= 0) {
50
+ await redis.del(key);
51
+ }
52
}
53
54
export async function checkForgotPasswordAttempt(ip: string): Promise<boolean> {
0 commit comments