refactor: atualizações e remoção de módulos não utilizados
This commit is contained in:
@@ -20,7 +20,7 @@ export class TokenBlacklistService {
|
||||
|
||||
const blacklistKey = this.buildBlacklistKey(token);
|
||||
const ttl = expiresIn || this.calculateTokenTTL(decoded);
|
||||
|
||||
|
||||
await this.redis.set(blacklistKey, 'blacklisted', ttl);
|
||||
} catch (error) {
|
||||
throw new Error(`Erro ao adicionar token à blacklist: ${error.message}`);
|
||||
@@ -45,7 +45,7 @@ export class TokenBlacklistService {
|
||||
async clearUserBlacklist(userId: number): Promise<void> {
|
||||
const pattern = `auth:blacklist:${userId}:*`;
|
||||
const keys = await this.redis.keys(pattern);
|
||||
|
||||
|
||||
if (keys.length > 0) {
|
||||
await this.redis.del(...keys);
|
||||
}
|
||||
@@ -59,12 +59,16 @@ export class TokenBlacklistService {
|
||||
|
||||
private calculateTokenTTL(payload: JwtPayload): number {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const exp = payload.exp || (now + 8 * 60 * 60);
|
||||
const exp = payload.exp || now + 8 * 60 * 60;
|
||||
return Math.max(0, exp - now);
|
||||
}
|
||||
|
||||
private hashToken(token: string): string {
|
||||
const crypto = require('crypto');
|
||||
return crypto.createHash('sha256').update(token).digest('hex').substring(0, 16);
|
||||
return crypto
|
||||
.createHash('sha256')
|
||||
.update(token)
|
||||
.digest('hex')
|
||||
.substring(0, 16);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user