fix(salix): refs #7272 #7272 Call validateToken

This commit is contained in:
Javier Segarra 2024-04-30 11:26:31 +02:00
parent 6277c3da09
commit 43cedef259
1 changed files with 16 additions and 51 deletions

View File

@ -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);