From 8efc5fb52749c28bc1534874a70e5e4f4cad445b Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 28 Oct 2022 16:01:38 -0700 Subject: switch ip geolocate api's --- lib/register.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'lib/register.js') diff --git a/lib/register.js b/lib/register.js index 60f8825f..6f8f366b 100644 --- a/lib/register.js +++ b/lib/register.js @@ -1,3 +1,4 @@ +import countries from "$lib/countries"; import config from "$config"; import { authenticator } from "otplib"; import db from "$db"; @@ -16,22 +17,14 @@ export default async (user, ip, requireChallenge) => { user.password = await bcrypt.hash(user.password, 1); } - let countries = { - CA: "CAD", - US: "USD", - JP: "JPY", - CN: "CNY", - AU: "AUD", - GB: "GBP" - }; - - if (!config.ipstack || ip.startsWith("127") || ip.startsWith("192")) + if (!config.ipxapi || ip.startsWith("127") || ip.startsWith("192")) { user.currency = "CAD"; - else { - let info = await axios.get( - `http://api.ipstack.com/${ip}?access_key=${config.ipstack}` - ); - user.currency = countries[info.data.country_code] || "USD"; + } else { + let { data } = await axios.get(`https://ipxapi.com/api/ip?ip=${ip}`, { + headers: { authorization: `Bearer ${config.ipxapi}` } + }); + + user.currency = countries[data.countryCode] || "USD"; } user.currencies = [...new Set([user.currency, "CAD", "USD"])]; -- cgit v1.2.3