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'),
buildSchema() { const shape = {}; this.fields.forEach((field) => { shape[field.name] = field.forImport(); }); return yup .object() .shape(shape) .noUnknown(true); }
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.' }); } }
Yup.object().shape({ email: Yup.string().email(), oldPassword: Yup.string().min(6), password: Yup.string() .min(6) .when('oldPassword', (oldPassword, field) => oldPassword ? field.required() : field ), passwordConfirm: Yup.string().when('password', (password, field) => password ? field.required().oneOf([Yup.ref('password')]) : field ), })
const create = async (req, res, next) => { try { const schema = Yup.object().shape({ name: Yup.string().required(), 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.' }); } }
buildSchema() { const shape = {}; this.fields.forEach((field) => { shape[field.name] = field.forFormCast(); }); return yup.object().shape(shape); }
Yup.object().shape({ name: Yup.string(), email: Yup.string().email(), oldPassword: Yup.string().min(6), password: Yup.string() .min(6) .when('oldPassword', (oldPassword, field) => oldPassword ? field.required() : field ), confirmPassword: Yup.string().when('password', (password, field) => password ? field.required().oneOf([Yup.ref('password')]) : field ), })
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.forExport(); }); return yup .object() .shape(shape) .noUnknown(true); }
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); }
buildSchema() { const shape = {}; this.fields.forEach((field) => { shape[field.name] = field.forImport(); }); return yup .object() .shape(shape) .noUnknown(true); }
buildSchema() { const shape = {}; this.fields.forEach((field) => { shape[field.name] = field.forExport(); }); return yup .object() .shape(shape) .noUnknown(true); }