Skip to content
Back

Issue with Retrieving User IP Address Using Appwrite: Getting Wrong Location Data

  • 0
  • Functions
Osmanlı
25 Feb, 2025, 19:38

Hello, I’m using Appwrite to authenticate a user and then retrieve their IP address. However, when I try to get the user's IP address, it seems to return the server's IP address instead of the actual user's IP address.

Here’s the issue:

I authenticate the user using Appwrite. I use the locale.get() function to retrieve the user's IP address. However, the IP address returned points to the server's location, not the actual user's. Has anyone encountered this issue? Any suggestions on how to fix this?

TypeScript
  `  const userClient = new Client()
        .setEndpoint('https://cloud.appwrite.io/v1')
        .setProject('project')
        .setJWT(req.headers['x-appwrite-user-jwt']);

    const account = new Account(userClient);
    const user = await account.get();
    const userId = user.$id;

    if (userId) {

        const locale = new Locale(userClient);

        const result = await locale.get();

        return res.json(result, 200);
    }`

response: { "ip": "138.68.98.28", "countryCode": "DE", "country": "Germany", "continentCode": "EU", "continent": "Europe", "eu": true, "currency": "" }

TL;DR
Developers are experiencing an issue where Appwrite returns the server's IP address instead of the user's when trying to retrieve location data. To fix this, developers can use the X-Real-IP or X-Forwarded-For headers in their API gateway or Nginx configuration to pass the user's IP address to Appwrite.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more