要检查用户的视图是否正常工作或是否在用户视点之外进行更改(在开发中),对某个用户进行化身化非常有用。
我如何使用Meteor执行此操作? Best是一个独立于帐户身份验证的解决方案。
答案 0 :(得分:6)
要在生产中模拟用户,您可以在服务器上调用setUserId
,在客户端调用Meteor.connection.setUserId
。有关详细信息,请参阅我的blog post。
答案 1 :(得分:3)
如果您使用Meteor.userId()
和Meteor.user()
在javascript中识别您的人,则可以使用此类内容覆盖客户端js
Meteor.userId = function (impersonate_id) {
return (impersonate_id) ? impersonate_id : Meteor.default_connection.userId();
}
Meteor.user = function (impersonate_id) {
var userId = Meteor.userId(impersonate_id);
if (!userId)
return null;
return Meteor.users.findOne(userId);
}
现在当您使用Meteor.userId
或Meteor.user
修改代码时,无论您在何处使用Meteor.user
& Meteor.userId
接受一个论点。因此,当您想要模拟用户时,只需将您要登录的用户的_id
参数传递给
Meteor.user("1"); //Loads the data for user with _id 1
Meteor.user(); //Loads the actual logged in user
此功能仅在您实际上是管理员且您的发布功能允许您查看所有用户数据时才有效