#48: call authentication.logout for each revoked account

This commit is contained in:
SleepWalker
2016-11-15 07:55:15 +02:00
parent 9e7d5b8338
commit 5142d65b39
7 changed files with 214 additions and 73 deletions

View File

@@ -59,7 +59,10 @@ export function revoke(account) {
if (accountToReplace) {
return dispatch(authenticate(accountToReplace))
.then(() => dispatch(remove(account)));
.then(() => {
authentication.logout(account);
dispatch(remove(account));
});
}
return dispatch(logout());
@@ -111,8 +114,19 @@ export function activate(account) {
};
}
export function logoutAll() {
return (dispatch, getState) => {
const {accounts: {available}} = getState();
available.forEach((account) => authentication.logout(account));
dispatch(reset());
};
}
export const RESET = 'accounts:reset';
/**
* @api private
*
* @return {object} - action definition
*/
export function reset() {

View File

@@ -1,7 +1,7 @@
import { routeActions } from 'react-router-redux';
import accounts from 'services/api/accounts';
import { reset as resetAccounts } from 'components/accounts/actions';
import { logoutAll } from 'components/accounts/actions';
import authentication from 'services/api/authentication';
import { setLocale } from 'components/i18n/actions';
@@ -54,24 +54,16 @@ export function setUser(payload) {
export function logout() {
return (dispatch, getState) => {
if (getState().user.token) {
authentication.logout();
}
dispatch(setUser({
lang: getState().user.lang,
isGuest: true
}));
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(logoutAll());
dispatch(resetAccounts());
dispatch(routeActions.push('/login'));
dispatch(routeActions.push('/login'));
resolve();
}, 0);
});
return Promise.resolve();
};
}