I have two LoopBack models, A and B. Part of their code is like this:
A.beforeRemote('create', function (ctx, unused, next) {
...
B.findById(idForB, callBack);
...
});
B.observe('access', function (ctx, next) {
const token = ctx.options && ctx.options.accessToken;
const userId = token && token.userId;
ctx.query = ctx.query ? ctx.query : {};
ctx.query.where = ctx.query.where ? ctx.query.where : {};
ctx.query.where.allowedUserId = userId;
});
Now, B's access observe hook has accessToken when REST calls are directly made from B/ API.
However, when making an API POST A/ API call, A's beforeRemote hook on create attempts to call B.findById which in turn triggers B's access observe hook, but in this scenario, there is no accessToken; not even option.
How do I propagate access information from A to B?
via Khan 'Sadh' Mostafa
No comments:
Post a Comment