fix: Implement frontend IP lookup to get accurate user location#73
Merged
fix: Implement frontend IP lookup to get accurate user location#73
Conversation
- Add lookup-user-ip utility with multi-API fallback support - Update current-user service to use frontend IP lookup instead of backend - Fixes issue where server IP was returned instead of user IP - Supports geoiplookup.io and ipapi.co with automatic fallback - Implements localStorage caching (1 hour TTL) - Graceful fallback to browser timezone when all APIs fail This resolves the critical bug where users see incorrect city/country during onboarding because the backend returns the server's location instead of the user's actual location.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The current whois/IP lookup implementation has a critical bug: it retrieves the server's IP address instead of the user's IP address, resulting in incorrect geolocation data during onboarding.
Example: User in New York → Server in Frankfurt → Onboarding shows Frankfurt, Germany ❌
Root Cause
request()->ip()which returns server IP when behind proxy/load balancerSolution
This PR implements frontend IP lookup using free geolocation APIs to get accurate user location data.
Changes Made
New Utility:
addon/utils/lookup-user-ip.jsUpdated Service:
addon/services/current-user.jslookup/whoiscall with frontendlookupUserIp()this.currentUser.whois('city')still works)Benefits
✅ Accurate Location: Gets user's actual IP, not server IP
✅ Faster: 50% faster (1 network hop vs 2)
✅ No API Key Required: Uses free APIs (geoiplookup.io, ipapi.co)
✅ Reliable: Multi-API fallback ensures high availability
✅ Cached: Reduces API calls with localStorage caching
Testing
Tested with:
Related Issues
Fixes the whois/IP lookup issue identified in fleetbase/internals onboarding where users see incorrect city/country data.
Migration Notes
currentUser.whois()continues to work/lookup/whoisendpoint can remain for backwards compatibility