mirror of
https://github.com/strapi/strapi.git
synced 2025-07-11 11:03:46 +00:00
39 lines
967 B
JavaScript
39 lines
967 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const { yup } = require('@strapi/utils');
|
||
|
const { YupValidationError } = require('@strapi/utils').errors;
|
||
|
|
||
|
const callbackBodySchema = yup.object().shape({
|
||
|
identifier: yup.string().required(),
|
||
|
password: yup.string().required(),
|
||
|
});
|
||
|
|
||
|
const registerBodySchema = yup.object().shape({
|
||
|
email: yup
|
||
|
.string()
|
||
|
.email()
|
||
|
.required(),
|
||
|
password: yup.string().required(),
|
||
|
});
|
||
|
|
||
|
const sendEmailConfirmationBodySchema = yup.object().shape({
|
||
|
email: yup
|
||
|
.string()
|
||
|
.email()
|
||
|
.required(),
|
||
|
});
|
||
|
|
||
|
const validateSchema = schema => async (body, errorMessage) => {
|
||
|
try {
|
||
|
await schema.validate(body, { strict: true, abortEarly: false });
|
||
|
} catch (e) {
|
||
|
throw new YupValidationError(e, errorMessage);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
module.exports = {
|
||
|
validateCallbackBody: validateSchema(callbackBodySchema),
|
||
|
validateRegisterBody: validateSchema(registerBodySchema),
|
||
|
validateSendEmailConfirmationBody: validateSchema(sendEmailConfirmationBodySchema),
|
||
|
};
|