const isValidEmail = value => {
console.log(value);
const endpoint = process.env.REACT_APP_EMAIL_VALIDATION;
return Object.keys(value).forEach(item => {
const url = `${endpoint}&email=${value[item].email}`;
const name = item + ".email";
if (value[item].email) {
axios
.get(url)
.then(result => {
const isValid = result.data.format_valid;
if (!isValid) {
const err = {};
err[item + ".email"] = "That email is taken";
console.log({ ...err });
throw { ...err };
}
})
.catch(e => {
console.log(e);
});
}
});
const isValidEmail = email => {
console.log(email);
const endpoint = process.env.REACT_APP_EMAIL_VALIDATION;
const url = `${endpoint}&email=${email}`;
return axios.get(url).then(result => {
return result.data.format_valid;
});
};
Promise {pending}