Skip to content

Instantly share code, notes, and snippets.

@kvnam
Created November 27, 2018 10:49
Show Gist options
  • Save kvnam/984fec16e2c3b03b7185272d1fe525b2 to your computer and use it in GitHub Desktop.
Save kvnam/984fec16e2c3b03b7185272d1fe525b2 to your computer and use it in GitHub Desktop.
ReactPress Token validation
export const validateToken = (url) => {
return dispatch => {
let token = null, email = null;
if(localStorage.getItem("token")){
token = localStorage.getItem("token");
email = localStorage.getItem("email");
}
if(token){
axios.post("/simple-jwt-authentication/v1/token/validate", {},{headers: {"Authorization": "Bearer " + token}}).then(res => {
if(res.data.data.status === 200){
dispatch({type: actionTypes.VALIDATE_TOKEN_SUCCESS, token:token, email:email, redirectTo: url});
}
}).catch(err => {
//TODO: HANDLE VALIDATION ERROR
});
}else{
//TODO: HANDLE NO TOKEN
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment