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
在Accounts.OnCreateUser Meteor JS中获取客户端IP_Meteor_Meteor Accounts - Fatal编程技术网

在Accounts.OnCreateUser Meteor JS中获取客户端IP

在Accounts.OnCreateUser Meteor JS中获取客户端IP,meteor,meteor-accounts,Meteor,Meteor Accounts,我正在尝试获取客户端IP地址 Accounts.onCreateUser((options, user) => { var data = { "updated_at" : new Date(), "registration_ip" : user.connection.clientAddress, "recruiter" : "SELF", "registration_time" : new Date(), }; _.exten

我正在尝试获取客户端IP地址

Accounts.onCreateUser((options, user) => {

  var data = {
      "updated_at" : new Date(),
      "registration_ip" : user.connection.clientAddress,
      "recruiter" : "SELF",
      "registration_time" : new Date(),
  };

  _.extend(user.profile, data);
  return user;
});
我得到的错误是:

I20170511-19:11:26.792(5.5)? Exception while invoking method 'createUser' 
TypeError: Cannot read property 'clientAddress' of undefined

如何在此处获取客户端IP地址?

这是我用来获取用户IP地址的代码

Accounts.validateLoginAttempt(function (attempt) {
    /* Before any checks save user first time login attempt IP address */
    let IPAddress = Global.getNestedValue(attempt, 'connection.httpHeaders.x-forwarded-for');

    if (IPAddress && attempt.user && !attempt.user.firstTimeIP) {
        Meteor.users.update({ _id: attempt.user._id }, { $set: { firstTimeIP: IPAddress } })
    }
}

user.connection
是否返回任何内容?另外,当您尝试此连接时会发生什么情况?@blueren:谢谢您的回复。它返回“undefined”。如果用户经常登录Hanks,您可能需要检索它,我会尝试让您知道。