diff --git a/app/portainer/__module.js b/app/portainer/__module.js index b312bcd40..6ba28a35a 100644 --- a/app/portainer/__module.js +++ b/app/portainer/__module.js @@ -12,7 +12,7 @@ async function initAuthentication(authManager, Authentication, $rootScope, $stat } }); - await Authentication.init(); + return await Authentication.init(); } angular.module('portainer.app', ['portainer.oauth']).config([ @@ -24,34 +24,23 @@ angular.module('portainer.app', ['portainer.oauth']).config([ name: 'root', abstract: true, resolve: { - initStateManager: [ - 'StateManager', - 'Authentication', - 'Notifications', - 'authManager', - '$rootScope', - '$state', - '$async', - '$q', - (StateManager, Authentication, Notifications, authManager, $rootScope, $state, $async, $q) => { - const deferred = $q.defer(); + initStateManager: /* @ngInject */ function initStateManager($async, StateManager, Authentication, Notifications, authManager, $rootScope, $state) { + return $async(async () => { const appState = StateManager.getState(); if (!appState.loading) { - deferred.resolve(); - } else { - StateManager.initialize() - .then(function success() { - return $async(initAuthentication, authManager, Authentication, $rootScope, $state); - }) - .then(() => deferred.resolve()) - .catch(function error(err) { - Notifications.error('Failure', err, 'Unable to retrieve application settings'); - deferred.reject(err); - }); + return; } - return deferred.promise; - }, - ], + try { + const loggedIn = await initAuthentication(authManager, Authentication, $rootScope, $state); + await StateManager.initialize(); + if (!loggedIn) { + $state.go('portainer.auth'); + } + } catch (err) { + Notifications.error('Failure', err, 'Unable to retrieve application settings'); + } + }); + }, }, views: { 'sidebar@': { diff --git a/app/portainer/services/authentication.js b/app/portainer/services/authentication.js index 82ce17de8..ed43666f6 100644 --- a/app/portainer/services/authentication.js +++ b/app/portainer/services/authentication.js @@ -29,6 +29,7 @@ angular.module('portainer.app').factory('Authentication', [ if (jwt) { await setUser(jwt); } + return !!jwt; } catch (error) { throw error; }