7565-testToMaster #2567

Merged
alexm merged 250 commits from 7565-testToMaster into master 2024-06-11 06:31:18 +00:00
1 changed files with 28 additions and 8 deletions
Showing only changes of commit b4284889e1 - Show all commits

View File

@ -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) {
constructor($http, $q, vnApp, $translate, $state, $transitions, $window, vnToken, vnModules) {
Object.assign(this, {
$http,
$q,
vnApp,
$translate,
$state,
$transitions,
$window,
@ -38,12 +40,28 @@ export default class Auth {
};
if (this.vnToken.token) {
return this.validateToken()
.then(() => true)
.catch(err => {
console.error(err);
redirectToLogin();
});
const loadWithRetry = () => {
return this.validateToken()
.then(() => true)
.catch(err => {
switch (err.status) {
case 400:
case 401:
redirectToLogin();
break;
default:
return new Promise(resolve => {
setTimeout(() => {
this.vnApp.showMessage(this.$translate.instant('Loading...'));
resolve(loadWithRetry());
}, 2000);
});
}
console.error(err);
});
};
return loadWithRetry();
} else
return redirectToLogin();
});
@ -124,6 +142,8 @@ export default class Auth {
});
}
}
Auth.$inject = ['$http', '$q', '$state', '$transitions', '$window', 'vnToken', 'vnModules'];
Auth.$inject = [
'$http', '$q', 'vnApp', '$translate', '$state',
'$transitions', '$window', 'vnToken', 'vnModules'];
ngModule.service('vnAuth', Auth);