aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/nostr.js1
-rw-r--r--lib/passport.js5
-rw-r--r--lib/register.js15
-rw-r--r--lib/sockets.js26
-rw-r--r--lib/utils.js21
-rw-r--r--lib/whitelist.js1
6 files changed, 21 insertions, 48 deletions
diff --git a/lib/nostr.js b/lib/nostr.js
index ad089bb5..08ed8b61 100644
--- a/lib/nostr.js
+++ b/lib/nostr.js
@@ -142,7 +142,6 @@ pool.on("event", async (relay, sub, ev) => {
};
await redis.set(`user:${pubkey}`, JSON.stringify(user));
- await redis.set(`user:${user.username}`, JSON.stringify(user));
coinos.send(ev);
} else if (sub.includes("follows")) {
let pubkey = sub.split(":")[0];
diff --git a/lib/passport.js b/lib/passport.js
index b559b2f9..25dc0103 100644
--- a/lib/passport.js
+++ b/lib/passport.js
@@ -34,8 +34,9 @@ fastifyPassport.use(
},
async (payload, next) => {
try {
- let { uuid } = payload;
- let user = await g(`user:${uuid}`);
+ let { id } = payload;
+ let user = await g(`user:${id}`);
+ user.haspin = !!user.pin;
next(null, user);
} catch (e) {
console.log("payload", payload);
diff --git a/lib/register.js b/lib/register.js
index 9f18c15e..8ac5355f 100644
--- a/lib/register.js
+++ b/lib/register.js
@@ -14,8 +14,8 @@ export default async (user, ip, requireChallenge) => {
if (!username) throw new Error("Username required");
username = username.replace(/ /g, "");
- let uuid = v4();
- user.uuid = uuid;
+ let id = v4();
+ user.id = id;
let exists = await g(`user:${username}`);
if (exists) throw new Error(`Username ${username} taken`);
@@ -24,8 +24,6 @@ export default async (user, ip, requireChallenge) => {
user.password = await bcrypt.hash(password, 1);
}
- console.log("BOO");
-
if (!config.ipxapi || ip.startsWith("127") || ip.startsWith("192")) {
user.currency = "CAD";
} else {
@@ -53,14 +51,9 @@ export default async (user, ip, requireChallenge) => {
user.ip = ip;
}
- console.log("user uuid", user.uuid, user.username);
+ await s(`user:${id}`, user);
+ await s(`user:${user.username}`, id);
- try {
- await s(`user:${user.uuid}`, user);
- await s(`user:${user.username}`, user);
- } catch (e) {
- console.log("HUH", e);
- }
l("new user", user.username);
return user;
};
diff --git a/lib/sockets.js b/lib/sockets.js
index 0f343937..c94c29a0 100644
--- a/lib/sockets.js
+++ b/lib/sockets.js
@@ -8,7 +8,7 @@ import { differenceInSeconds, subSeconds } from "date-fns";
import fastifyWs from "@fastify/websocket";
import whitelist from "./whitelist";
import { l, err, warn } from "$lib/logging";
-import { getUser } from "$lib/utils";
+import { g } from "$lib/redis";
const code = 1000;
@@ -92,24 +92,24 @@ app.register(async function(app) {
if (!token || token === "null" || !jwt.decode(token))
return ws.close(code, `bad token ${token}`);
- let { uuid } = jwt.decode(token);
- if (!uuid) throw new Error("Invalid JWT token");
- console.log("UUID", uuid)
- let user = await getUser(uuid);
+ let { id: user_id } = jwt.decode(token);
+ if (!user_id) throw new Error("Invalid JWT token");
+ let user = await g(`user:${user_id}`);
if (!user) throw new Error("User not found");
+ user.haspin = !!user.pin;
- if (!store.sockets[uuid]) store.sockets[uuid] = {};
- const existing = Object.keys(store.sockets[uuid]);
+ if (!store.sockets[user_id]) store.sockets[user_id] = {};
+ const existing = Object.keys(store.sockets[user_id]);
if (existing.length > 4) {
- const p = existing.find(sid => sid !== id);
- store.sockets[uuid][p].send(JSON.stringify({ type: "logout" }));
+ const p = existing.find(sid => sid !== user_id);
+ store.sockets[user_id][p].send(JSON.stringify({ type: "logout" }));
setTimeout(() => {
- if (store.sockets[uuid][p])
- store.sockets[uuid][p].close(code, "too many sockets");
+ if (store.sockets[user_id][p])
+ store.sockets[user_id][p].close(code, "too many sockets");
}, 5000);
}
- store.sockets[uuid][id] = ws;
- names[id] = uuid;
+ store.sockets[user_id][id] = ws;
+ names[id] = user_id;
ws.user = user;
ws.send(
diff --git a/lib/utils.js b/lib/utils.js
index 559f8531..b556c46a 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -1,7 +1,6 @@
import store from "$lib/store";
import { g } from "$lib/redis";
import config from "$config";
-import ln from "$lib/ln";
export const nada = () => {};
@@ -18,15 +17,6 @@ export const requirePin = async ({ body, user }) => {
throw new Error("Invalid pin");
};
-export const getUser = async (uuid) => {
- let user = g(`user:${uuid}`);
- if (!user) throw new Error("user not found");
-
- user.haspin = !!user.pin;
-
- return user;
-};
-
export const prod = process.env.NODE_ENV === "production";
export const fail = msg => {
throw new Error(msg);
@@ -35,14 +25,5 @@ export const fail = msg => {
export const SATS = 100000000;
export const toSats = n => Math.round(n * SATS);
-export const derivePayRequest = async ({ amount, memo, tip }) => {
- if (!tip) tip = 0;
- let value = amount + tip;
-
- if (!memo) memo = "coinos";
- return (
- await ln.invoice(value ? `${value}sat` : "any", new Date(), memo, 360)
- ).bolt11;
-};
-
export const uniq = (a, k) => [...new Map(a.map(x => [k(x), x])).values()];
+export const pick = (O, K) => K.reduce((o, k) => ((o[k] = O[k]), o), {});
diff --git a/lib/whitelist.js b/lib/whitelist.js
index 523e9d37..49cc9af3 100644
--- a/lib/whitelist.js
+++ b/lib/whitelist.js
@@ -25,7 +25,6 @@ export default [
"symbol",
"theme",
"twofa",
- "uuid",
"unit",
"username",
"verified"