1

How can we get the user's IP address when using functions.auth.user().onCreate(...)? Basically, I want to track the IP address from when a user visits our website and the IP address from when they sign up on the app for analytics purposes, unless someone knows a better way! Thanks.

Doug Stevenson
  • 268,359
  • 30
  • 341
  • 380
arao6
  • 3,176
  • 5
  • 27
  • 48

1 Answers1

3

This is not possible in any Cloud Functions background trigger. If you want to attempt to record an IP address (which may not be very accurate or helpful, given that network traffic can go through proxies and VPNs), you will have to use an HTTP type trigger that was invoked from your app or web site running on the the user's computer or device. The request might include a header called x-forwarded-for or fastly-client-ip that contains an IP address. But this isn't documented, so there is no guarantee this will exist.

See also: How to get client IP address in a Firebase cloud function?

Doug Stevenson
  • 268,359
  • 30
  • 341
  • 380