#7272 - BUG Redirect To Login when ACL not exists #2371

Merged
jsegarra merged 19 commits from 7272_bug_redirectToLogin into dev 2024-05-27 06:56:20 +00:00
1 changed files with 16 additions and 51 deletions
Showing only changes of commit 43cedef259 - Show all commits

View File

@ -38,31 +38,12 @@ export default class Auth {
}; };
if (this.vnToken.token) { if (this.vnToken.token) {
const maxRetries = 5; return this.validateToken()
let retryCount = 0;
const retryDelay = 2000; // Milisegundos (1 segundo)
const loadAclsWithRetry = () => {
return this.loadAcls(maxRetries)
.then(() => true) .then(() => true)
.catch(error => { .catch(err => {
retryCount++; console.error(err);
if (retryCount < maxRetries) { redirectToLogin();
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();
} else } else
return redirectToLogin(); return redirectToLogin();
}); });
@ -132,33 +113,17 @@ export default class Auth {
return promise; return promise;
} }
loadAcls(maxRetries = 1) { validateToken() {
const attemptLoad = retryCount => { return this.$http.get('VnUsers/validateToken')
return this.aclService.load()
.then(() => { .then(() => {
this.loggedIn = true; this.loggedIn = true;
this.vnModules.reset(); this.vnModules.reset();
}) })
.catch(err => { .catch(err => {
if (retryCount >= maxRetries) {
this.vnToken.unset();
throw err; 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);
}
} }
Auth.$inject = [ Auth.$inject = ['$http', '$q', '$state', '$transitions', '$window', 'vnToken', 'vnModules'];
'$http', '$q', 'vnApp', '$translate', '$state',
'$transitions', '$window', 'vnToken', 'vnModules',
'aclService'];
ngModule.service('vnAuth', Auth); ngModule.service('vnAuth', Auth);