我如何登录从流星特定用户的shell

问题描述:

我上的流星应用程序的工作。我打开了流星壳。我需要做一个快速测试插入,但我需要假装我作为一个特定的用户(我知道userId)进行身份验证。在流星壳里面,有没有办法让我作为userId的特定用户登录?我如何登录从流星特定用户的shell

谢谢!

你无法模拟登录的用户在流星壳。

我不知道究竟是什么,你的测试,但如果是一些允许/拒绝对收集规则,尝试创建方法做你的东西,请以希望用户和呼叫方法。

也在里面方法可以运行this.setUserId(userId)。这只需设置用于此连接上未来方法调用的userId的值即可。

meteor shell,您可以访问到服务器,这是不依赖于特定的用户会话。相反,您需要从客户端模拟用户(在浏览器中打开控制台)。在服务器上

@impersonateUser = (userId) -> Meteor.call "impersonate", userId, (err,res) -> if err console.log err else Meteor.connection.setUserId res._id console.log 'Now impersonating ' + res.emails[0].address

这:

试试这个客户端上的

Meteor.methods impersonate: (query) -> throw new Meteor.Error(403, "Permission denied") unless Meteor.user().isAdmin u = Meteor.users.findOne(query) throw new Meteor.Error(404, "User not found") unless u @setUserId u._id return u

然后在客户端上运行impersonateUser('someUserId')