mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Force logout when backend is offline
This commit is contained in:
parent
5d5096a695
commit
4c795701b4
3 changed files with 11 additions and 13 deletions
|
@ -65,6 +65,7 @@ class App extends Component {
|
|||
return {
|
||||
simulations: SimulationStore.getState(),
|
||||
currentUser: UserStore.getState().currentUser,
|
||||
token: UserStore.getState().token,
|
||||
|
||||
runningSimulators: simulators
|
||||
};
|
||||
|
@ -96,10 +97,11 @@ class App extends Component {
|
|||
|
||||
componentWillUpdate(nextProps, nextState) {
|
||||
// check if user is still logged in
|
||||
if (UserStore.getState().token == null) {
|
||||
//this.props.router.push('/login');
|
||||
if (nextState.token == null) {
|
||||
// discard local token
|
||||
localStorage.setItem('token', '');
|
||||
|
||||
//return;
|
||||
this.props.router.push('/login');
|
||||
}
|
||||
|
||||
// open connection to each required simulator
|
||||
|
|
|
@ -28,14 +28,14 @@ class Home extends Component {
|
|||
AppDispatcher.dispatch({
|
||||
type: 'users/logout'
|
||||
});
|
||||
|
||||
// discard login token
|
||||
localStorage.setItem('token', '');
|
||||
}
|
||||
|
||||
componentWillUpdate(nextProps, nextState) {
|
||||
// check if logged out
|
||||
if (nextState.currentUser == null) {
|
||||
// discard login token
|
||||
localStorage.setItem('token', '');
|
||||
|
||||
if (nextState.token == null) {
|
||||
// transition to login page
|
||||
nextProps.router.push('/login');
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@ class UserStore extends ReduceStore {
|
|||
}
|
||||
|
||||
reduce(state, action) {
|
||||
console.log(action.type);
|
||||
|
||||
switch (action.type) {
|
||||
case 'users/login':
|
||||
UsersDataManager.login(action.username, action.password);
|
||||
|
@ -35,11 +33,10 @@ class UserStore extends ReduceStore {
|
|||
|
||||
case 'users/logout':
|
||||
// delete user and token
|
||||
return Object.assign({}, state, { token: null, currentUser: null });
|
||||
return Object.assign({}, state, { token: null });
|
||||
|
||||
case 'users/logged-in':
|
||||
// request logged-in user data
|
||||
console.log(action.token);
|
||||
UsersDataManager.getCurrentUser(action.token);
|
||||
|
||||
return Object.assign({}, state, { token: action.token });
|
||||
|
@ -50,8 +47,7 @@ class UserStore extends ReduceStore {
|
|||
|
||||
case 'users/current-user-error':
|
||||
// discard user token
|
||||
//return { currentUser: null, token: null };
|
||||
return state;
|
||||
return Object.assign({}, state, { currentUser: null, token: null });
|
||||
|
||||
case 'users/login-error':
|
||||
console.log(action);
|
||||
|
|
Loading…
Add table
Reference in a new issue