Created
January 24, 2020 15:01
-
-
Save AshutoshSajan/7bd50a2d33f231d05d126fd46e54a904 to your computer and use it in GitHub Desktop.
This file contains 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
function handleLogin (){ | |
let user = { | |
userName: 'Jhon Doe', | |
email: '[email protected]', | |
password: 'superstar@123' | |
} | |
const BASE_URL = 'http://localhost:3000/api/v1' | |
fetch(BASE_URL + '/users/login', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify(user) | |
}) | |
//here we are getting the response and converting that response into json format. | |
.then(res => res.json()) | |
.then(data => { | |
// we get data over here and we can use it now | |
console.log(data, 'user login data'); | |
if (data.success) { | |
sending data to reducer | |
this.props.dispatch({ type: 'LOGIN', payload: data }); | |
} else if (!data.success) { | |
console.log('login user unsuccessfull...'); | |
this.props.history.push('/users/login'); | |
} | |
}) | |
.catch(err => { | |
console.log(err, 'login user catch err...'); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment