I'm getting undefined when I try to assign user._id to an entity in a before hook.
The hook
module.exports = (options = {}) => {
return async context => {
const user = context.params.user;
context.data = {
...
userId: user._id,
...
};
return context;
};
};
This is my hooks register
before: {
...
create: [processProperty(), authenticate('jwt')],
...
}
}
I was able to fix the issue by bringing the
authenticatehook before myprocessPropertyhook as shown below. I think this is because each hook in the array is processed from left to right, so in this case, theprocessPropertyhook needs access to the authenticated user, so it needs to come after theauthenticatehook has been processed.