aboutsummaryrefslogtreecommitdiffstats
path: root/lib/register.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-10-28 16:02:07 -0700
committerAdam Soltys <[email protected]>2022-10-28 16:02:07 -0700
commita498bfc1ef952e75da26c16d838bae89faf10cfc (patch)
treeb557b82bc72c862a92470b6b710cd67571ebbf9b /lib/register.js
parentf46e553dd40439e18710225e6a0736b2fdebf57c (diff)
parent8efc5fb52749c28bc1534874a70e5e4f4cad445b (diff)
downloadcoinos-server-a498bfc1ef952e75da26c16d838bae89faf10cfc.tar.gz
coinos-server-a498bfc1ef952e75da26c16d838bae89faf10cfc.zip
Merge branch 'master' into prod
Diffstat (limited to 'lib/register.js')
-rw-r--r--lib/register.js23
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"])];