在Accounts.OnCreateUser Meteor JS中获取客户端IP
我正在尝试获取客户端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
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,您可能需要检索它,我会尝试让您知道。