I'm trying to validate a email field on a sign up form to check if it already exist. To do this I'm checking the running a GET request on the server that returns true and false.
This is my validation Schema for the field:
validationSchema={
yup.object().shape({
registrationEmail: yup.string().email('Invalid email').test('Unique Email','Email already in use', async (value) => {axios.get('http://localhost:5000/users/register', value).catch(err => console.log(err)) })
})
}
The problem seems to be that the values field is blank. How do I past the value from the Formik Field to my function?
EDIT: Managed to send value using the following
registrationEmail: yup.string().email('Invalid email').test('Unique Email','Email already in use', function(value){return new Promise((resolve, reject) => {axios.get('http://localhost:5000/users/register', value)})})
I'm still having troubles returning a response this is what the route looks like
router.get('/register', (req, res) => {
User.findOne({email: req.body.email}).then(user => {
if(user){
return true
}else{
return false
}
})
})