#181: fix logout for guests. Increase logout speed

This commit is contained in:
SleepWalker
2016-08-07 20:26:29 +03:00
parent 3d8c646a94
commit 322325d4ad
2 changed files with 87 additions and 56 deletions

View File

@@ -49,14 +49,24 @@ export function setUser(payload) {
}
export function logout() {
return (dispatch, getState) =>
authentication.logout().then(() => {
dispatch(setUser({
lang: getState().user.lang,
isGuest: true
}));
dispatch(routeActions.push('/login'));
return (dispatch, getState) => {
if (getState().user.token) {
authentication.logout();
}
return new Promise((resolve) => {
setTimeout(() => { // a tiny timeout to allow logout before user's token will be removed
dispatch(setUser({
lang: getState().user.lang,
isGuest: true
}));
dispatch(routeActions.push('/login'));
resolve();
}, 0);
});
};
}
export function fetchUserData() {