7565-testToMaster #2567
|
@ -7,10 +7,12 @@ import UserError from 'core/lib/user-error';
|
|||
* @property {Boolean} loggedIn Whether the user is currently logged
|
||||
*/
|
||||
export default class Auth {
|
||||
constructor($http, $q, $state, $transitions, $window, vnToken, vnModules, aclService) {
|
||||
constructor($http, $q, vnApp, $translate, $state, $transitions, $window, vnToken, vnModules, aclService) {
|
||||
Object.assign(this, {
|
||||
$http,
|
||||
$q,
|
||||
vnApp,
|
||||
$translate,
|
||||
$state,
|
||||
$transitions,
|
||||
$window,
|
||||
|
@ -39,9 +41,31 @@ export default class Auth {
|
|||
};
|
||||
|
||||
if (this.vnToken.token) {
|
||||
return this.loadAcls()
|
||||
.then(() => true)
|
||||
.catch(redirectToLogin);
|
||||
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();
|
||||
} else
|
||||
return redirectToLogin();
|
||||
});
|
||||
|
@ -113,18 +137,33 @@ export default class Auth {
|
|||
return promise;
|
||||
}
|
||||
|
||||
loadAcls() {
|
||||
return this.aclService.load()
|
||||
.then(() => {
|
||||
this.loggedIn = true;
|
||||
this.vnModules.reset();
|
||||
})
|
||||
.catch(err => {
|
||||
this.vnToken.unset();
|
||||
throw err;
|
||||
});
|
||||
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('Error al cargar los ACLs'));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Start loading with retry
|
||||
return attemptLoad(1);
|
||||
}
|
||||
}
|
||||
Auth.$inject = ['$http', '$q', '$state', '$transitions', '$window', 'vnToken', 'vnModules', 'aclService'];
|
||||
Auth.$inject = [
|
||||
'$http', '$q', 'vnApp', '$translate', '$state',
|
||||
'$transitions', '$window', 'vnToken', 'vnModules',
|
||||
'aclService'];
|
||||
|
||||
ngModule.service('vnAuth', Auth);
|
||||
|
|
Loading…
Reference in New Issue