Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- authenticate() {
- fetch(this.state.authenticationURL, {
- headers: {
- "Content-Type": "application/json"
- },
- credentials: "include",
- method: "POST",
- body: JSON.stringify({
- username: this.state.username,
- password: this.state.password
- })
- })
- .then(response => {
- if (!response.ok) {
- response.json().then(error => {
- this.setState({
- showAlert: true,
- alertType: "danger",
- alertMessage: error.message
- });
- });
- Cookies.remove("userid");
- Cookies.remove("firstname");
- Cookies.remove("token");
- }
- return response.json();
- })
- .then(data => {
- this.setState({
- showAlert: true,
- alertType: "success",
- alertMessage: "Success!!"
- });
- Cookies.set("userid", data.userid);
- Cookies.set("firstname", data.firstname);
- Cookies.set("Token", data.token);
- window.location = this.state.redirectURL;
- })
- .catch(error => {
- console.error("Error cannot communicate with the API Server.");
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement