From 43cedef2597b580d03b1b4e7df08e98486c91d9d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 30 Apr 2024 11:26:31 +0200 Subject: [PATCH] fix(salix): refs #7272 #7272 Call validateToken --- front/core/services/auth.js | 67 +++++++++---------------------------- 1 file changed, 16 insertions(+), 51 deletions(-) diff --git a/front/core/services/auth.js b/front/core/services/auth.js index c3aa6a3c7..28feb1090 100644 --- a/front/core/services/auth.js +++ b/front/core/services/auth.js @@ -38,31 +38,12 @@ export default class Auth { }; if (this.vnToken.token) { - const maxRetries = 5; - let retryCount = 0; - const retryDelay = 2000; // Milisegundos (1 segundo) - - const loadAclsWithRetry = () => { - return this.loadAcls(maxRetries) - .then(() => true) - .catch(error => { - retryCount++; - if (retryCount < maxRetries) { - return new Promise(resolve => { - setTimeout(() => { - this.vnApp.showMessage(this.$translate.instant('Loading...')); - resolve(loadAclsWithRetry(maxRetries - retryCount)); - }, retryDelay); - }); - } else { - // Retry limit reached, redirect to login - return redirectToLogin(); - } - }); - }; - - // Start loading ACLs with retry - return loadAclsWithRetry(); + return this.validateToken() + .then(() => true) + .catch(err => { + console.error(err); + redirectToLogin(); + }); } else return redirectToLogin(); }); @@ -132,33 +113,17 @@ export default class Auth { return promise; } - loadAcls(maxRetries = 1) { - const attemptLoad = retryCount => { - return this.aclService.load() - .then(() => { - this.loggedIn = true; - this.vnModules.reset(); - }) - .catch(err => { - if (retryCount >= maxRetries) { - this.vnToken.unset(); - throw err; - } else { - // Retry after delay - return new Promise((resolve, reject) => { - reject(new Error(this.$translate.instant('Error loading ACLs'))); - }); - } - }); - }; - - // Start loading with retry - return attemptLoad(1); + validateToken() { + return this.$http.get('VnUsers/validateToken') + .then(() => { + this.loggedIn = true; + this.vnModules.reset(); + }) + .catch(err => { + throw err; + }); } } -Auth.$inject = [ - '$http', '$q', 'vnApp', '$translate', '$state', - '$transitions', '$window', 'vnToken', 'vnModules', - 'aclService']; +Auth.$inject = ['$http', '$q', '$state', '$transitions', '$window', 'vnToken', 'vnModules']; ngModule.service('vnAuth', Auth);