Skip to content

Comments

fix: Update phone-input to use frontend IP lookup from ember-core#117

Merged
roncodes merged 5 commits intomainfrom
fix/use-frontend-ip-lookup
Feb 24, 2026
Merged

fix: Update phone-input to use frontend IP lookup from ember-core#117
roncodes merged 5 commits intomainfrom
fix/use-frontend-ip-lookup

Conversation

@roncodes
Copy link
Member

Problem

The phone-input component was using the backend lookup/whois endpoint which returns the server's IP location instead of the user's IP location. This caused incorrect country code detection for phone number formatting.

Example: User in New York → Server in Frankfurt → Phone input defaults to Germany ❌


Solution

Updated phone-input component to use the new frontend IP lookup utility from ember-core that correctly returns the user's actual location.


Changes

Updated Component

  • addon/components/phone-input.js
    • Import lookupUserIp utility from @fleetbase/ember-core
    • Replace fetch.get('lookup/whois') with lookupUserIp()
    • Update error handling and debug messages

Other Components Verified

The following components use currentUser.getOption('whois') to read cached whois data and do NOT need updates:

  • coordinates-input.js - Uses cached latitude/longitude
  • currency-select.js - Uses cached currency code
  • money-input.js - Uses cached currency code

These components automatically benefit from the ember-core fix without any changes.


Benefits

Accurate Detection: Gets user's actual country code, not server location
Faster: 1 network hop instead of 2
No Backend Dependency: Direct API call from browser
Consistent: Aligns with other components using whois cache
Better UX: Phone input defaults to correct country


Dependencies

Requires: fleetbase/ember-core PR #73 (Frontend IP lookup utility)

The phone-input component now imports lookupUserIp from ember-core, so ember-core must be updated first.


Testing

Manual Testing

  1. Open phone input component in different geographic locations
  2. Verify country code defaults to user's actual location
  3. Test with VPN to verify it follows VPN location
  4. Test error handling when API fails

Expected Behavior

  • User in US → Phone input defaults to +1 (US)
  • User in UK → Phone input defaults to +44 (UK)
  • User in Japan → Phone input defaults to +81 (JP)

Migration Notes

  • No breaking changes
  • Backward compatible
  • No database changes required
  • Works immediately after ember-core update is deployed

Manus AI and others added 5 commits February 24, 2026 01:43
Changes:
- Import lookupUserIp utility from @fleetbase/ember-core
- Replace backend fetch.get('lookup/whois') with frontend lookupUserIp()
- Update error handling and debug messages

This fixes the issue where phone-input was getting server IP location
instead of user IP location. Now uses the new frontend IP lookup utility
that correctly returns the user's actual location.

Benefits:
- Accurate country code detection for phone number formatting
- Faster lookup (1 network hop vs 2)
- No backend dependency
- Consistent with other components using currentUser.whois cache

Depends on: fleetbase/ember-core PR #73 (frontend IP lookup utility)
Changes:
- Remove failure callback parameter (not needed)
- Always call success() callback, never failure()
- Default to 'us' country code if IP lookup fails or returns no country code
- Update debug messages to reflect fallback behavior

This ensures the phone input always initializes properly even if:
- IP lookup API is down
- User is behind firewall/VPN that blocks geolocation APIs
- API returns incomplete data

Better UX: Phone input always works, defaults to US (+1) on any error.
Ember's debug() function doesn't accept multiple parameters like console.log().
Must use string concatenation with + operator instead.
@roncodes roncodes merged commit 3a15f3d into main Feb 24, 2026
7 checks passed
@roncodes roncodes deleted the fix/use-frontend-ip-lookup branch February 24, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant