password: 'Password123' }} validationSchema={Yup.object().shape({ email: Yup.string().email('Must be a valid email').max(255).required('Email is required'), password: Yup.string().max(255).required('Password is required')
}} validationSchema={ Yup.object().shape({ email: Yup.string().email('Must be a valid email').max(255).required('Email is required'), firstName: Yup.string().max(255).required('First name is required'),
schema.validate(req.body).catch(e => { error = { message: e.message, field: e.path }; })
const login = async (req, res, next) => { try { const schema = Yup.object().shape({ email: Yup.string().email().required(), password: Yup.string().required().min(6), }); await schema.validate(req.body, { abortEarly: false }); return next(); } catch (error) { return res.status(400).json({ error: 'Verifique os campos acima.' }); } }
const validate = (value) => { try { schema.validateSync({ name: value }); } catch (e) { return e.errors; } }
LoginSchema.validate(req.body) .then(() => next()) .catch(error => res.status(422).json({ [error.path]: error.message }) )
buildSchema() { const shape = {}; this.fields.forEach((field) => { shape[field.name] = field.forFormCast(); }); return yup.object().shape(shape); }
buildSchema() { const shape = {}; this.fields.forEach((field) => { shape[field.name] = field.forFilter(); }); return yup.object().shape(shape); }
buildSchema() { const shape = {}; this.fields.forEach((field) => { shape[field.name] = field.forForm(); }); return yup.object().shape(shape); }
castSchema() { const shape = {}; this.fields.forEach((field) => { shape[field.name] = field.forFilterCast(); }); return yup.object().shape(shape); }