diff --git a/front/core/services/auth.js b/front/core/services/auth.js index 28feb1090..3337dfdb6 100644 --- a/front/core/services/auth.js +++ b/front/core/services/auth.js @@ -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);