From 43e6f784c7cc74cee683d9b8ec066bc7fd89e27a Mon Sep 17 00:00:00 2001 From: IP2Location Date: Wed, 31 Jul 2024 09:55:12 +0800 Subject: [PATCH] Added IP2Location.io API --- app/hooks/use-device-location.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/hooks/use-device-location.ts b/app/hooks/use-device-location.ts index 8775e98c70..a3f08b3f33 100644 --- a/app/hooks/use-device-location.ts +++ b/app/hooks/use-device-location.ts @@ -32,7 +32,16 @@ const useDeviceLocation = () => { setCountryCode(_countryCode) updateCountryCode(client, _countryCode) } else { - console.warn("no data. default of SV will be used") + const response2 = await axios.get("https://api.ip2location.io/", { + timeout: 5000, + }) + const _countryCode2 = response2?.data?.country_code + if (_countryCode2) { + setCountryCode(_countryCode2) + updateCountryCode(client, _countryCode2) + } else { + console.warn("no data. default of SV will be used") + } } // can throw a 429 for device's rate-limiting. resort to cached value if available } catch (err) {