mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
#48: call authentication.logout for each revoked account
This commit is contained in:
@@ -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() {
|
||||
|
@@ -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();
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user