Client connection and IP in Accounts.onCreateUser

Hey - I’m trying to validate a captcha from a signup form and I would like to so within Accounts.onCreateUser (this is where it makes the most sense to me anyway).

Thing is, I’m not sure how to retrieve the user IP address. Too bad since validateLoginAttempt does expose connection I don’t understand why onCreateUser doesn’t do the same…

2 Likes

Were you able to figure something out for this?

Yes, but not really proud of what I did. Essentially, I have to call a method getUserIP from the client that retrieves the user IP address with this.connection.clientAddress, and then pass the result to Account.createUser({username, email, password, captcha: {value, remoteip}).

This is a bit stupid since this makes two method calls to the server, but I don’t have any other idea atm…

In Meteor version 1.5.2 inside Accounts.onCreateUser(function(options, user) { ... });
this.connection is undefined

In 2021, is it possible to access to the client address from Accounts.onCreateUser() using this.connection or another way?
I tried various solutions with no luck.

The system call Accounts.validateLoginAttempt before Accounts.onCreateUser(), you can somehow store the client address at the first call then use in the second one.

1 Like