aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-07-12 21:52:56 -0700
committerAdam Soltys <[email protected]>2020-07-12 21:52:56 -0700
commit17b85b21c5e3a1a8bd31d2623b6c2358eb1513d6 (patch)
tree9e265d9c7e9e635a4d27c9f54a991756f6578976
parent4b28676d3bf53b6e4bf82d62d39308838ce8ffc3 (diff)
downloadcoinos-server-17b85b21c5e3a1a8bd31d2623b6c2358eb1513d6.tar.gz
coinos-server-17b85b21c5e3a1a8bd31d2623b6c2358eb1513d6.zip
fix find or create key
-rw-r--r--routes/lnurl.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/routes/lnurl.js b/routes/lnurl.js
index 86cb5a76..709e1fc5 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -324,6 +324,8 @@ lnurlServer.bindToHook(
lnurlServer.bindToHook("login", async (key) => {
l.info("logging in");
try {
+ if (!key) throw new Error("login key not defined");
+
const exists = await db.Key.findOne({
where: { hex: key },
include: [{ model: db.User, as: "user" }],
@@ -337,15 +339,17 @@ lnurlServer.bindToHook("login", async (key) => {
});
if (user) {
- const k = await db.Key.findOrCreate({
+ const [k, created] = await db.Key.findOrCreate({
where: {
user_id: user.id,
hex: key,
},
});
- l.info("added key", username, k);
- emit(username, "key", k);
+ if (created) {
+ l.info("added key", username, k);
+ emit(username, "key", k);
+ }
} else {
l.info("user not found");
user = await register({