Hi, Can we get header(authorization) and insert it as a userId?
Here is my code
const ratingSchema = Joi.object().keys({
ratings: Joi.number().precision(2),
comment_added: Joi.date().timestamp('javascript').default(() => Date(new Date()), 'creation date'),
commentId: Joi.number().integer().default(new Date().getTime().toString())
});`
const schemas = {
createReviews: {
headers: {
authorization: Joi.string().required()
},
params: {
Id: Joi.string().regex(/^[A-Fa-f0-9]{24}$/).required()
},
body: {
comment_added: Joi.date().timestamp('javascript').default(() => Date(new Date()), 'creation date'),
commentId: Joi.number().integer().default(new Date().getTime().toString()),
userId: ? (Here I want to take authorisation and it should auto insert. Can you please tell How can I do it?)
}
}
};`
in userId I want to take authorization key and insert it as a userId. Please tell me How can I do it
Assuming you use hapi you use the onPostAuth hook for that, I don't think Joi can do what you want it to do
can you please give an example using above code using hapi
.default(Joi.ref('$headers.authorization')) might work, or something similar.
Most helpful comment
.default(Joi.ref('$headers.authorization'))might work, or something similar.