aboutsummaryrefslogtreecommitdiffstats
path: root/lib/register.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/register.js')
-rw-r--r--lib/register.js23
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"])];