2

我最近更新了代码的某些部分,并想检查它们是否与生产数据库配合良好,生产数据库为不同的用户提供不同的数据集。但我只能以我自己的用户身份访问该应用程序。

如何通过其他用户的眼光看待 Meteor 应用程序?

4

3 回答 3

2

I wrote a blog post about it. But here are the details:

On the server. Add a method that only an admin can call that would change the currently logged user programatically:

Meteor.methods(
  "switchUser": (username) ->
    user = Meteor.users.findOne("username": username)
    if user
      idUser = user["_id"]
      this.setUserId(idUser)
      return idUser
)

On the client. Call this method with the desired username and override the user on the client as well:

Meteor.call("switchUser", "usernameNew", function(idUser) {
    Meteor.userId = function() { return idUser;};
});

Refresh client to undo.

This may not be a very elegant solution but it does the trick.

于 2013-08-03T18:52:37.963 回答
2

更新:最好的方法是使用一种方法

服务器端

Meteor.methods({
    logmein: function(user_id_to_log_in_as) {
        this.setUserId(user_id_to_log_in_as);
    }
}):

客户端

Meteor.call("logmein", "<some user_id of who you want to be>");

为了清楚起见,这保持简单,请随意放置在您自己的安全措施中。

于 2013-08-03T17:01:45.637 回答
0

略微更新了接受的答案,以将客户端作为新用户以及服务器登录。

logmein: function(user_id_to_log_in_as) {
  if (Meteor.isServer) {
    this.setUserId(user_id_to_log_in_as);
  }
  if (Meteor.isClient) {
    Meteor.connection.setUserId(user_id_to_log_in_as);
  }
},

更多信息在这里:http ://docs.meteor.com/api/methods.html#DDPCommon-MethodInvocation-setUserId

于 2016-06-06T04:02:57.030 回答