Created
November 27, 2018 10:49
-
-
Save kvnam/984fec16e2c3b03b7185272d1fe525b2 to your computer and use it in GitHub Desktop.
ReactPress Token validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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