7525-devToTest #2542

Merged
alexm merged 231 commits from 7525-devToTest into test 2024-06-04 07:59:34 +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);