I have a login form in React Js which submits user details on button click.
What I am trying to get is when user submit details an API of user data is called which returns a list of the user. Then when The code gets user list I check if the user is present in the list or not.
I am stuck after the result has come.
I want to return true or false
to setstate
of Error but instead I get undefined.
This is the function which runs
let handleSubmit = (e) => {
e.preventDefault();
let result;
result = validateLogin(formDetails.name, formDetails.password);
console.log("------------", result); //getting undefined instead of True or false
}
ValidateLogin:
let validateLogin = async (email, password) => {
const response = await axios.get('https://fakestoreapi.com/users');
if (response) {
const k = response.data.find(user => {
return user.email === email && user.password === password
})
if (k) {
return true
} else {
return false
}
}
}