fix: fix refresh token race condition
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user