Skip to content

Lost key after validation #2431

@sarhugo

Description

@sarhugo

Hi, not sure if this is a problem of Joi itself or the integration with Hapi.
I'm doing the following validation in a route:

server.route({
    method: 'POST',
    path: '/register',
    config: {
      validate: {
        payload: Joi.object({
          username: Joi.string().regex(/^[a-z0-9_\.]+$/i).required(),
          email: Joi.string().email().required(),
          password: Joi.string().min(6).required(),
          confirm: Joi.object().keys({
            email: Joi.string().required(),
            password: Joi.string().required()
          }).required()
        }).assert('confirm.email', Joi.ref('email'))
          .assert('confirm.password', Joi.ref('password'))
          .required()
        , options: {abortEarly: false}
      },
     handler: function() {}
   });

The problem is with the assert validation. If I send different emails and passwords I get the following response:

{ statusCode: 400,
  error: 'Bad Request',
  message: 'value validation failed because confirm.email failed to pass the assertion test. value validation failed because confirm.password failed to pass the assertion test',
  validation: { source: 'payload', keys: [ 'value', 'value' ] } }

Shouldn't the keys be 'confirm.email' and 'confirm.password' instead of 'value'? Am I doing something wrong?

Thanks

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions