Handle logout
This commit is contained in:
parent
bbd4edf226
commit
6ead42b06d
|
@ -177,17 +177,16 @@ export function logIn(username, password) {
|
|||
export function logOut() {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const me = state.getIn(['auth', 'me']);
|
||||
|
||||
dispatch({ type: AUTH_LOGGED_OUT });
|
||||
|
||||
// Attempt to destroy OAuth token on logout
|
||||
api(getState).post('/oauth/revoke', {
|
||||
return api(getState).post('/oauth/revoke', {
|
||||
client_id: state.getIn(['auth', 'app', 'client_id']),
|
||||
client_secret: state.getIn(['auth', 'app', 'client_secret']),
|
||||
token: state.getIn(['auth', 'user', 'access_token']),
|
||||
token: state.getIn(['auth', 'users', me, 'access_token']),
|
||||
}).finally(() => {
|
||||
dispatch({ type: AUTH_LOGGED_OUT, accountId: me });
|
||||
dispatch(snackbar.success('Logged out.'));
|
||||
});
|
||||
|
||||
dispatch(snackbar.success('Logged out.'));
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { openModal } from '../../../actions/modal';
|
||||
import { fetchOwnAccounts } from 'soapbox/actions/auth';
|
||||
import { throttle } from 'lodash';
|
||||
import PropTypes from 'prop-types';
|
||||
|
@ -65,11 +64,6 @@ class ProfileDropdown extends React.PureComponent {
|
|||
};
|
||||
}
|
||||
|
||||
handleAddAccount = e => {
|
||||
this.props.dispatch(openModal('LOGIN'));
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
fetchOwnAccounts = throttle(() => {
|
||||
this.props.dispatch(fetchOwnAccounts());
|
||||
}, 2000);
|
||||
|
|
|
@ -47,7 +47,7 @@ const maybeShiftMe = state => {
|
|||
}
|
||||
};
|
||||
|
||||
const importFailedToken = (state, token) => {
|
||||
const deleteToken = (state, token) => {
|
||||
return state.withMutations(state => {
|
||||
state.update('tokens', ImmutableMap(), tokens => tokens.delete(token));
|
||||
state.update('users', ImmutableMap(), users => users.filterNot(user => user.get('access_token') === token));
|
||||
|
@ -55,6 +55,14 @@ const importFailedToken = (state, token) => {
|
|||
});
|
||||
};
|
||||
|
||||
const deleteUser = (state, accountId) => {
|
||||
return state.withMutations(state => {
|
||||
state.update('users', ImmutableMap(), users => users.delete(accountId));
|
||||
state.update('tokens', ImmutableMap(), tokens => tokens.filterNot(token => token.get('account') === accountId));
|
||||
maybeShiftMe(state);
|
||||
});
|
||||
};
|
||||
|
||||
// Upgrade the initial state
|
||||
const migrateLegacy = state => {
|
||||
if (localState) return state;
|
||||
|
@ -104,11 +112,11 @@ const reducer = (state, action) => {
|
|||
case AUTH_LOGGED_IN:
|
||||
return importToken(state, action.token);
|
||||
case AUTH_LOGGED_OUT:
|
||||
return state.set('user', ImmutableMap());
|
||||
return deleteUser(state, action.accountId);
|
||||
case VERIFY_CREDENTIALS_SUCCESS:
|
||||
return importCredentials(state, action.token, action.account);
|
||||
case VERIFY_CREDENTIALS_FAIL:
|
||||
return importFailedToken(state, action.token);
|
||||
return deleteToken(state, action.token);
|
||||
case SWITCH_ACCOUNT:
|
||||
return state.set('me', action.accountId);
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue