diff --git a/hooks/useIpAddress.tsx b/hooks/useIpAddress.tsx index 5ce15ff..9368227 100644 --- a/hooks/useIpAddress.tsx +++ b/hooks/useIpAddress.tsx @@ -36,10 +36,17 @@ export default function useIpAddress() { useEffect(() => { const checkIpLocation = async () => { - const response = await fetch(`https://www.cloudflare.com/cdn-cgi/trace`) - const parsedResponse = await response.text() - const ipLocation = parsedResponse.match(/loc=(.+)/) - const ipCountryCode = ipLocation ? ipLocation[1] : '' + let ipCountryCode + try { + const response = await fetch(`https://www.cloudflare.com/cdn-cgi/trace`) + const parsedResponse = await response.text() + const ipLocation = parsedResponse.match(/loc=(.+)/) + ipCountryCode = ipLocation ? ipLocation[1] : '' + } catch { + const response = await fetch(`https://countrycode.bonfida.workers.dev/`) + const parsedResponse = await response.json() + ipCountryCode = parsedResponse.countryCode + } if (ipCountryCode) { setIpAllowed(!SANCTIONED_COUNTRY_CODES.includes(ipCountryCode))