Proceso completo de solicitud de activacion

This commit is contained in:
2026-01-29 12:57:51 +01:00
parent 4acc04fb51
commit 68ae3aea57
14 changed files with 138 additions and 107 deletions

View File

@@ -118,11 +118,7 @@ export class JWTService {
return token
}
public async getAccessToken() {
if (this.authToken != undefined && !this.authToken.isExpired()) {
console.warn("Se está intentado conseguir un token sin expirar el anterior")
}
public async getNewTokens() {
const bodyWithtoken = {
...DEFAULT_BODY,
client_assertion: this.buildJwtBody()
@@ -151,6 +147,25 @@ export class JWTService {
}
}
public async getAccessToken() {
// Caso 1: El token actual es valido
if (this.authToken != undefined && !this.authToken.isExpired()) {
return this.authToken
}
// Caso 2: El token ha expirado pero se puede refrescar
if (this.authToken?.isExpired() && this.refreshToken != undefined && !this.refreshToken.isExpired()) {
await this.tryRefreshToken()
}
// Caso 3: Ningún token es valido
await this.getNewTokens()
if (this.authToken == undefined) throw new Error("Error obteniendo tokens de auth")
return this.authToken
}
public async tryRefreshToken() {
if (this.refreshToken == undefined) throw new Error("El refreshToken no está definido")
if (this.refreshToken.isExpired()) throw new Error("El refreshToken ha expirado")