diff options
| author | Adam Soltys <[email protected]> | 2023-02-21 16:20:11 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-02-21 16:20:11 -0800 |
| commit | 7d4f1ae952f3230c5a020ed9c4afe3c968ac099f (patch) | |
| tree | f406bac26d93ccfb2ecfd14a7a5230c2d6561c1d | |
| parent | 681304b3a0ccff942e07d5f889af33898abd4c19 (diff) | |
| download | coinos-server-7d4f1ae952f3230c5a020ed9c4afe3c968ac099f.tar.gz coinos-server-7d4f1ae952f3230c5a020ed9c4afe3c968ac099f.zip | |
switch to ipregister
| -rw-r--r-- | lib/register.js | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/register.js b/lib/register.js index 135bc041..d222a363 100644 --- a/lib/register.js +++ b/lib/register.js @@ -2,7 +2,7 @@ import countries from "$lib/countries"; import config from "$config"; import { authenticator } from "otplib"; import bcrypt from "bcrypt"; -import { l } from "$lib/logging"; +import { l, warn } from "$lib/logging"; import { v4 } from "uuid"; import { s, g } from "$lib/db"; import { got } from "got"; @@ -25,19 +25,20 @@ export default async (user, ip, requireChallenge) => { } user.currency = "USD"; - if (config.ipxapi) { - let countryCode = "US"; - + if (config.ipregistry) { try { - let r = await got(`https://ipxapi.com/api/ip?ip=${ip}`, { - headers: { authorization: `Bearer ${config.ipxapi}` } - }).json(); - if (r.success) ({ countryCode } = r); + let { + location: { + country: { code } + } + } = await got( + `https://api.ipregistry.co/${ip}?key=${config.ipregistry}&fields=location.country.code` + ).json(); + + user.currency = countries[code]; } catch (e) { - console.log(e); + warn("unable to detect country from IP", username); } - - user.currency = countries[countryCode]; } user.currencies = [...new Set([user.currency, "CAD", "USD"])]; |
