Please answer the following questions for yourself before submitting an issue.
I am calling an action, and the action has ctx.meta available. as I set it during authorize phase.
In hooks -> after, I change some response based on condition and emit an event.
Emitting event has all data but missing meta. When I access ctx.meta, it is empty.
It should have ctx.meta available.
in hooks, after phase, emit an event, this.broker.emit('user..created', data, ['test']);
try to access, ctx.meta, It is empty
https://codesandbox.io/s/moleculer-sample-forked-wji7t?file=/index.js
const broker = new ServiceBroker({
logger: console,
transporter: "NATS"
});
broker.createService({
name: "test",
events: {
"user.created": {
async handler(ctx) {
console.log("Hello Meta: ", ctx.meta);
}
}
},
actions: {
create(ctx) {
ctx.meta.isAllowed = true;
const newUser = {
id: 1,
name: 'any',
isAllowed: ctx.meta.isAllowed
}
return newUser;
}
},
hooks: {
after: {
async create(ctx, res) {
ctx.broker.emit('user.created', res, ['test']);
return res;
}
}
}
});
Correct example: https://codesandbox.io/s/moleculer-sample-forked-3lget
Most helpful comment
Correct example: https://codesandbox.io/s/moleculer-sample-forked-3lget