Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (dispatch: Dispatch, state: GetState) => {
const { oAuthToken: tokenToRevoke, socialNetwork } = state().user;
dispatch({ type: LOGOUT_REQUEST });
dispatch({ type: RESET_STATE });
try {
await CookieManager.clearAll();
const social = socialNetwork || socialNetworkFallback;
switch (social) {
case 'google': {
if (tokenToRevoke) {
await revoke(oAuth.google, { tokenToRevoke });
}
break;
}
case 'facebook':
await LoginManager.logOut();
break;
default:
break;
}
return dispatch({ type: SET_LOGIN_STATUS, payload: true });
} catch (e) {
console.error(e);
return dispatch({ type: SET_LOGIN_STATUS, payload: false });
}
};
}
return getRefreshToken().then(refreshToken => {
if (refreshToken) {
revoke(config, { tokenToRevoke: refreshToken });
}
});
}, () => {
revoke = async () => {
try {
await revoke(config, {
tokenToRevoke: this.state.accessToken,
sendClientId: true
});
this.animateState({
accessToken: '',
accessTokenExpirationDate: '',
refreshToken: '',
beers: []
});
} catch (error) {
Alert.alert('Failed to revoke token', error.message);
}
};
revoke = async () => {
try {
await revoke(config, {
tokenToRevoke: this.state.accessToken,
sendClientId: true,
});
this.animateState({
accessToken: '',
accessTokenExpirationDate: '',
refreshToken: '',
});
} catch (error) {
Alert.alert('Failed to revoke token', error.message);
}
};
revoke = async () => {
try {
await revoke(config, {
tokenToRevoke: this.state.accessToken,
sendClientId: true
});
this.animateState({
accessToken: '',
accessTokenExpirationDate: '',
refreshToken: ''
});
} catch (error) {
Alert.alert('Failed to revoke token', error.message);
}
};