diff options
| author | Adam Soltys <[email protected]> | 2022-10-28 16:01:38 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-28 16:01:38 -0700 |
| commit | 8efc5fb52749c28bc1534874a70e5e4f4cad445b (patch) | |
| tree | 54118849cf8d6c33635d555ca9d41a9a693160d8 /lib/register.js | |
| parent | 740ec7ed160034ee435fc52fa0056b0fad708e59 (diff) | |
| download | coinos-server-8efc5fb52749c28bc1534874a70e5e4f4cad445b.tar.gz coinos-server-8efc5fb52749c28bc1534874a70e5e4f4cad445b.zip | |
switch ip geolocate api's
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"])]; |
