Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 以其他用户身份访问Meteor应用程序_Authentication_Meteor - Fatal编程技术网

Authentication 以其他用户身份访问Meteor应用程序

Authentication 以其他用户身份访问Meteor应用程序,authentication,meteor,Authentication,Meteor,我最近更新了代码的一些部分,希望检查它们是否与生产数据库配合良好,因为生产数据库为不同的用户提供了不同的数据集。但我只能以自己的用户身份访问应用程序 如何通过其他用户的眼睛看到Meteor应用程序?更新:最好的方法是使用一种方法 服务器端 客户端 为了清晰起见,这是保持简单的,请随意放置在您自己的安全措施中。更新:最好的方法是使用方法 服务器端 客户端 为了清晰起见,这是保持简单的,请随意放置在您自己的安全措施中。我写了一篇关于它的文章。但具体情况如下: 在服务器上。添加一个只有管理员才能调用的

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


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

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

服务器端

客户端


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

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

服务器端

客户端

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

我写了一篇关于它的文章。但具体情况如下:

在服务器上。添加一个只有管理员才能调用的方法,该方法将以编程方式更改当前登录的用户:

Meteor.methods(
  "switchUser": (username) ->
    user = Meteor.users.findOne("username": username)
    if user
      idUser = user["_id"]
      this.setUserId(idUser)
      return idUser
)
在客户机上。使用所需的用户名调用此方法,并覆盖客户端上的用户:

Meteor.call("switchUser", "usernameNew", function(idUser) {
    Meteor.userId = function() { return idUser;};
});
刷新客户端以撤消

这可能不是一个非常优雅的解决方案,但它确实起到了作用。

我写了一篇关于它的文章。但具体情况如下:

在服务器上。添加一个只有管理员才能调用的方法,该方法将以编程方式更改当前登录的用户:

Meteor.methods(
  "switchUser": (username) ->
    user = Meteor.users.findOne("username": username)
    if user
      idUser = user["_id"]
      this.setUserId(idUser)
      return idUser
)
在客户机上。使用所需的用户名调用此方法,并覆盖客户端上的用户:

Meteor.call("switchUser", "usernameNew", function(idUser) {
    Meteor.userId = function() { return idUser;};
});
刷新客户端以撤消


这可能不是一个非常优雅的解决方案,但它确实起到了作用。

稍微更新了已接受的答案,以便将客户端作为新用户登录到服务器上

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);
  }
},

此处的更多信息:

略微更新了已接受的答案,以新用户身份登录客户端和服务器

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);
  }
},

更多信息请点击此处:

这似乎不再有效,因为Meteor在services.resume.loginToken中使用哈希表;这是Meteor 1.1上的内容,但变化可能发生得更早。@Han是的,你说得对。我已使用在客户端控制台中运行的bestCall Meteor.connection.setUserIduserId方法更新了答案。注意:如果您刷新页面或手动更改URL,则您的用户将恢复为原来登录的用户。这花了我一点时间来看看发生了什么。这似乎不再有效,因为Meteor在services.resume.loginToken;这是Meteor 1.1上的内容,但变化可能发生得更早。@Han是的,你说得对。我已使用在客户端控制台中运行的bestCall Meteor.connection.setUserIduserId方法更新了答案。注意:如果您刷新页面或手动更改URL,则您的用户将恢复为原来登录的用户。这花了我一点时间来看看发生了什么。