diff options
| author | Adam Soltys <[email protected]> | 2020-07-12 21:52:56 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-07-12 21:52:56 -0700 |
| commit | 17b85b21c5e3a1a8bd31d2623b6c2358eb1513d6 (patch) | |
| tree | 9e265d9c7e9e635a4d27c9f54a991756f6578976 | |
| parent | 4b28676d3bf53b6e4bf82d62d39308838ce8ffc3 (diff) | |
| download | coinos-server-17b85b21c5e3a1a8bd31d2623b6c2358eb1513d6.tar.gz coinos-server-17b85b21c5e3a1a8bd31d2623b6c2358eb1513d6.zip | |
fix find or create key
| -rw-r--r-- | routes/lnurl.js | 10 |
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({ |
