如何直接设置登录用户?像
这样的东西Picker.route('sayhi', (params, req, res) => {
if (req.method === 'POST') {
const customUserId = getCustomUserId(req.headers);
Meteor.setUserId(customUserId);
console.log("hey I'm", Meteor.user());
res.end('ok');
}
});
答案 0 :(得分:2)
对于它的价值,这是它在流星内部完成的方式:
DDP._CurrentInvocation.withValue(new DDPCommon.MethodInvocation({
isSimulation: false, userId: getCustomUserId(req.headers),
}), function () {
// now things like Meteor.userId() work as expected
// also every method called here will get the right userId
});
此解决方案的唯一缺点是,使用某种可能随时间变化的私有API(或至少未记录的方法)感觉就像。如果你不害怕它,那么我相信这是一种可行的方式。
修改强>
正如@Guig在评论中提到的,还需要meteor add ddp-common
。
答案 1 :(得分:0)
您是否尝试允许管理员模仿用户?如果是这样,那么gwendall:impersonate包可能会对您有所帮助。
Impersonate.do(userId, callback)
或者您是否尝试以不同方式对用户进行身份验证?现有许多软件包可以通过各种方式进行身份验证。