1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

redirect after logout for external auth

This commit is contained in:
irismarie 2021-02-18 15:08:14 +01:00
parent 2b7a5fe81f
commit 8d74f92927
4 changed files with 46 additions and 15 deletions

View file

@ -45,6 +45,11 @@ class App extends React.Component {
constructor(props) {
super(props);
AppDispatcher.dispatch({
type: 'config/load',
});
this.state = {
showSidebarMenu: false,
}

View file

@ -46,8 +46,7 @@ class LoginStore extends ReduceStore {
return Object.assign({}, state, { config: action.data });
case 'config/load-error':
console.log("config load error");
return Object.assign({}, state, { config: null });
return Object.assign({}, state, { config: null});
case 'users/login':
UsersDataManager.login(action.username, action.password);

View file

@ -29,25 +29,28 @@ import LoginStore from './login-store'
import AppDispatcher from '../common/app-dispatcher';
class Login extends Component {
constructor(props) {
super(props);
static getStores(){
// load config in case the user goes directly to /login
// otherwise it will be loaded in app constructor
AppDispatcher.dispatch({
type: 'config/load',
});
}
static getStores() {
return [LoginStore]
}
static calculateState(prevState, props) {
// We need to work with the login store here to trigger the re-render upon state change after login
// Upon successful login, the token and currentUser are stored in the local storage as strings
const config = LoginStore.getState().config;
if (config === null) {
AppDispatcher.dispatch({
type: 'config/load',
});
}
return {
loginMessage: LoginStore.getState().loginMessage,
token: LoginStore.getState().token,
currentUser: LoginStore.getState().currentUser,
config: config,
config: LoginStore.getState().config,
}
}

View file

@ -17,12 +17,28 @@
import React from 'react';
import { Redirect } from 'react-router-dom';
import { Container } from 'flux/utils';
import AppDispatcher from '../common/app-dispatcher';
import Config from '../config.js';
import LoginStore from './login-store'
class Logout extends React.Component {
static getStores() {
return [LoginStore]
}
static calculateState(prevState, props) {
return {
config: LoginStore.getState().config,
}
}
componentDidMount() {
this.resetValues();
}
resetValues() {
AppDispatcher.dispatch({
type: 'users/logout'
});
@ -35,10 +51,18 @@ class Logout extends React.Component {
}
render() {
return (
<Redirect to="/login" />
);
if (this.state.config) {
let logout_url = _.get(this.props.config, ['authentication', 'logout_url'])
if (logout_url) {
this.resetValues();
window.location = logout_url;
}
}
return (
<Redirect to="/login" />
);
}
}
export default Logout;
let fluxContainerConverter = require('../common/FluxContainerConverter');
export default Container.create(fluxContainerConverter.convert(Logout));