ngx-sp-auth 4.20.0 → 4.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -796,13 +796,11 @@ class AuthStorageService {
796
796
  // visto que o método storageInitializeAutoStorage tem como objetivo realizar inicializações diversas quando o Login é executado via Pré Portal,
797
797
  // e não há necessidade de repetir essas inicializações a cada verificação do token.
798
798
  this._customStorageService.storageInitializeAutoStorage(); // Método com customizações para inicializações da AutoStorage
799
- this.reCheckLogin();
799
+ this.reCheckLogin(false);
800
800
  }
801
801
  }
802
- /**
803
- * Verifica a cada diferença de tempo entre a data atual e a data do token.
804
- */
805
- async reCheckLogin() {
802
+ /** Verifica a cada diferença de tempo entre a data atual e a data do token. */
803
+ async reCheckLogin(renew) {
806
804
  if (this.__authToken === undefined || this.__authToken === '' || this.authToken === null || this.authToken === '') {
807
805
  this.__isCheckingAuth = false;
808
806
  return;
@@ -817,8 +815,13 @@ class AuthStorageService {
817
815
  if (leftTime <= 0) {
818
816
  isRenewToken = true;
819
817
  }
820
- // TODO: Alterar aqui para não deslogar e avisar o usuário para logar denovo.
818
+ // Se o token estiver expirado ou prestes a expirar, tenta renovar o token. Se não conseguir renovar, desloga o usuário.
821
819
  if (isRenewToken) {
820
+ // Se o token não deve ser renovado, desloga o usuário. Caso contrário, tenta renovar o token. Se não conseguir renovar, desloga o usuário.
821
+ if (!renew) {
822
+ this.logout();
823
+ return;
824
+ }
822
825
  const response = await this.getNewToken();
823
826
  if (response !== undefined && response !== null && response != '') {
824
827
  this.authToken = response;
@@ -833,8 +836,8 @@ class AuthStorageService {
833
836
  if (this.ignoreCheckLogin)
834
837
  this.ignoreCheckLogin = false;
835
838
  this.isLoggedInSub.next(true);
836
- // A cada 30 segundos, o método reCheckLogin é chamado para verificar se o token ainda é válido ou se precisa ser renovado.
837
- setTimeout(this.reCheckLogin.bind(this), 30000);
839
+ // Chama a si próprio depois de um tempo igual ao tempo restante para o vencimento do token, para renovar o token ou deslogar o usuário.
840
+ setTimeout(this.reCheckLogin.bind(this, true), leftTime * 1000);
838
841
  }
839
842
  logout() {
840
843
  this.__isCheckingAuth = false;
@@ -4277,6 +4280,9 @@ class LoginGuard {
4277
4280
  */
4278
4281
  canLoad(_route, _segments) {
4279
4282
  if (_route.path === "auth/login" && this.authStorageService.isLoggedInSub.value && !this.authStorageService.isExternalLogin) {
4283
+ // TODO: Validar se usuário existe e se o domínio é o mesmo, caso contrário, deslogar o usuário e redirecionar para a tela de login
4284
+ // Possivelmente usar a mesma lógica do ValidateLogin no backend e a lógica do external-login.guard.ts
4285
+ // ...
4280
4286
  return this.router.createUrlTree(["/home"]);
4281
4287
  }
4282
4288
  return true;