【发布时间】:2016-09-16 09:15:39
【问题描述】:
我在尝试在模型的 remoteMethods 中恢复我的令牌的用户 ID 时遇到问题。我使用了以下代码:
User.beforeRemote('**', function(ctx, user, next) {
//...some custom token decoding
ctx.req.body.user_id = token.user_id;
console.log('token : ', token);
next();
});
然后,在我使用的模型中:
User.check = function (user_id, cb) {
// Do stuff..
};
User.remoteMethod(
'check',
{
http: {path: '/check', verb: 'post'},
returns: {arg: 'rate', type: 'object'},
accepts: [
{
arg: 'user_id',
type: 'number',
required: true,
description: "id of the user to check",
http: function getUserid(ctx) {
console.log('User.check http body : ', ctx.req.body);
return ctx.req.body.user_id;
}
}
],
description: ''
}
);
问题是我的 arg 函数“getUserid”在“User.beforeRemote”调用之前被触发。
这是一个错误吗?你知道我该怎么做吗? 我不想使用
arg : {http : {source : 'body'}},
因为我只想在远程方法中使用 user_id arg,而且我必须在大约 20~30 个现有方法中执行此操作
谢谢!
【问题讨论】:
标签: javascript token loopback