mirror of https://github.com/portainer/portainer
fix(auth): prevent double transition to logout (#4266)
* fix(auth): prevent double transition to logout * fix(app): revert * feat(state-manager): reinitalize on loginpull/4273/head
parent
6fa450a981
commit
0ebf0ab199
|
@ -7,7 +7,7 @@ async function initAuthentication(authManager, Authentication, $rootScope, $stat
|
||||||
// authManager.redirectWhenUnauthenticated() + unauthenticatedRedirector
|
// authManager.redirectWhenUnauthenticated() + unauthenticatedRedirector
|
||||||
// to have more controls on which URL should trigger the unauthenticated state.
|
// to have more controls on which URL should trigger the unauthenticated state.
|
||||||
$rootScope.$on('unauthenticated', function (event, data) {
|
$rootScope.$on('unauthenticated', function (event, data) {
|
||||||
if (!_.includes(data.config.url, '/v2/') && !_.includes(data.config.url, '/api/v4/')) {
|
if (!_.includes(data.config.url, '/v2/') && !_.includes(data.config.url, '/api/v4/') && isTransitionRequiresAuthentication($state.transition)) {
|
||||||
$state.go('portainer.logout', { error: 'Your session has expired' });
|
$state.go('portainer.logout', { error: 'Your session has expired' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -32,9 +32,8 @@ 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();
|
||||||
const nextTransition = $state.transition.to();
|
if (!loggedIn && isTransitionRequiresAuthentication($state.transition)) {
|
||||||
if (!loggedIn && !['portainer.logout', 'portainer.auth', 'portainer.init'].some((route) => nextTransition.name.startsWith(route))) {
|
$state.go('portainer.logout');
|
||||||
$state.go('portainer.auth');
|
|
||||||
return Promise.reject('Unauthenticated');
|
return Promise.reject('Unauthenticated');
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -425,3 +424,13 @@ angular.module('portainer.app', ['portainer.oauth']).config([
|
||||||
$stateRegistryProvider.register(team);
|
$stateRegistryProvider.register(team);
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
function isTransitionRequiresAuthentication(transition) {
|
||||||
|
const UNAUTHENTICATED_ROUTES = ['portainer.logout', 'portainer.auth'];
|
||||||
|
if (!transition) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const nextTransition = transition && transition.to();
|
||||||
|
const nextTransitionName = nextTransition ? nextTransition.name : '';
|
||||||
|
return !UNAUTHENTICATED_ROUTES.some((route) => nextTransitionName.startsWith(route));
|
||||||
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ angular.module('portainer.app').factory('StateManager', [
|
||||||
|
|
||||||
manager.clean = function () {
|
manager.clean = function () {
|
||||||
state.endpoint = {};
|
state.endpoint = {};
|
||||||
|
state.application = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
manager.updateLogo = function (logoURL) {
|
manager.updateLogo = function (logoURL) {
|
||||||
|
|
|
@ -147,6 +147,7 @@ class AuthenticationController {
|
||||||
}
|
}
|
||||||
|
|
||||||
async postLoginSteps() {
|
async postLoginSteps() {
|
||||||
|
await this.StateManager.initialize();
|
||||||
await this.checkForEndpointsAsync();
|
await this.checkForEndpointsAsync();
|
||||||
await this.checkForLatestVersionAsync();
|
await this.checkForLatestVersionAsync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,11 @@ angular.module('portainer.app').controller('InitAdminController', [
|
||||||
return Authentication.login(username, password);
|
return Authentication.login(username, password);
|
||||||
})
|
})
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
StateManager.updateEnableTelemetry($scope.formValues.enableTelemetry);
|
|
||||||
return SettingsService.update({ enableTelemetry: $scope.formValues.enableTelemetry });
|
return SettingsService.update({ enableTelemetry: $scope.formValues.enableTelemetry });
|
||||||
})
|
})
|
||||||
|
.then(() => {
|
||||||
|
return StateManager.initialize();
|
||||||
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return EndpointService.endpoints(0, 100);
|
return EndpointService.endpoints(0, 100);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue