fix(auth): don't redirect if route is unauthenticated (#4203)

* fix(auth): don't redirect if route is unauthenticated

* refactor(auth): replace resolve with onEnter

* fix(auth): throw error on init
feat4204-banner
Chaim Lev-Ari 2020-08-12 11:29:08 +03:00 committed by GitHub
parent 2c15dcd1f2
commit 201c3ac143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 18 deletions

View File

@ -23,8 +23,7 @@ angular.module('portainer.app', ['portainer.oauth']).config([
var root = { var root = {
name: 'root', name: 'root',
abstract: true, abstract: true,
resolve: { onEnter: /* @ngInject */ function onEnter($async, StateManager, Authentication, Notifications, authManager, $rootScope, $state) {
initStateManager: /* @ngInject */ function initStateManager($async, StateManager, Authentication, Notifications, authManager, $rootScope, $state) {
return $async(async () => { return $async(async () => {
const appState = StateManager.getState(); const appState = StateManager.getState();
if (!appState.loading) { if (!appState.loading) {
@ -33,16 +32,17 @@ angular.module('portainer.app', ['portainer.oauth']).config([
try { try {
const loggedIn = await initAuthentication(authManager, Authentication, $rootScope, $state); const loggedIn = await initAuthentication(authManager, Authentication, $rootScope, $state);
await StateManager.initialize(); await StateManager.initialize();
if (!loggedIn) { const nextTransition = $state.transition.to();
if (!loggedIn && !['portainer.logout', 'portainer.auth', 'portainer.init'].some((route) => nextTransition.name.startsWith(route))) {
$state.go('portainer.auth'); $state.go('portainer.auth');
return Promise.reject('Unauthenticated'); return Promise.reject('Unauthenticated');
} }
} catch (err) { } catch (err) {
Notifications.error('Failure', err, 'Unable to retrieve application settings'); Notifications.error('Failure', err, 'Unable to retrieve application settings');
throw err;
} }
}); });
}, },
},
views: { views: {
'sidebar@': { 'sidebar@': {
templateUrl: './views/sidebar/sidebar.html', templateUrl: './views/sidebar/sidebar.html',