2016-10-02 60 views
2

我上的流星應用程序的工作。我打開了流星殼。我需要做一個快速測試插入,但我需要假裝我作爲一個特定的用戶(我知道userId)進行身份驗證。在流星殼裏面,有沒有辦法讓我作爲userId的特定用戶登錄?我如何登錄從流星特定用戶的shell

謝謝!

回答

1

你無法模擬登錄的用戶在流星殼。

我不知道究竟是什麼,你的測試,但如果是一些允許/拒絕對收集規則,嘗試創建方法做你的東西,請以希望用戶和呼叫方法。

也在裏面方法可以運行this.setUserId(userId)。這隻需設置用於此連接上未來方法調用的userId的值即可。

0

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')