diff options
Diffstat (limited to 'lib/register.js')
| -rw-r--r-- | lib/register.js | 23 |
1 files changed, 8 insertions, 15 deletions
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"])]; |
