gpt4 book ai didi

meteor - 如何从 meteor 外壳以特定用户身份登录

转载 作者:行者123 更新时间:2023-12-03 23:57:46 25 4
gpt4 key购买 nike

我正在开发 Meteor 应用程序。我打开了 meteor shell 。我需要插入一个快速测试,但我需要假装我作为特定用户进行了身份验证(我知道 userId)。在 meteor shell 内部,有没有办法让我以给定 userId 的特定用户身份登录?

谢谢!

最佳答案

meteor shell使您可以访问与特定用户 session 无关的服务器。相反,您需要从客户端模拟用户(在浏览器中打开控制台)。

在客户端试试这个:
@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')在客户端上。

关于meteor - 如何从 meteor 外壳以特定用户身份登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39820204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com