fix: fix refresh token race condition

This commit is contained in:
2026-11-06 20:58:45 +03:30
parent 48e9ab5531
commit 2d32e2679b
3 changed files with 152 additions and 8 deletions
@@ -14,8 +14,18 @@ export class AuthRedisProvider {
await this.redisService.set(`rt:${jti}`, userId.toString(), ttl);
}
async hasRefreshToken(jti: string) {
return !!(await this.redisService.get(`rt:${jti}`));
async consumeRefreshToken(jti: string, userId: number): Promise<boolean> {
const consumed = await this.redisService.client.eval(
`if redis.call('GET', KEYS[1]) == ARGV[1] then
return redis.call('DEL', KEYS[1])
end
return 0`,
1,
`rt:${jti}`,
JSON.stringify(userId.toString()),
);
return consumed === 1;
}
async revokeRefreshToken(jti: string) {