Skip to content

Instantly share code, notes, and snippets.

@worst-developer
Created November 2, 2016 20:15
Show Gist options
  • Save worst-developer/ad9d9e4e76355536b1ec4d728b253062 to your computer and use it in GitHub Desktop.
Save worst-developer/ad9d9e4e76355536b1ec4d728b253062 to your computer and use it in GitHub Desktop.
export function checkToken () {
return async dispatch => {
const response = await httpGet(`/auth/validate-access-token/${localStorage.getItem('AuthToken')}`);
if (response.status !== 200) {
localStorage.removeItem('AuthToken');
dispatch({
type: Constants.TOKEN_ERROR,
error: response.statusText,
});
dispatch(push('/signin'));
}
if (response.status === 200 ) {
localStorage.getItem('AuthToken');
dispatch({
type: Constants.TOKEN_VALID,
payload: {
status: response.status,
statusText: 'TOKEN_VALID',
}
});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment