From 9b060ad4e907bf2a69d787e4a939ea30df0a3eb2 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 8 Nov 2022 02:36:12 -0800 Subject: otpsecret endpoint --- lib/utils.js | 2 +- routes/users.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index b4eb7ae4..48c351f0 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -11,7 +11,7 @@ import ln from "$lib/ln"; const { Op } = sequelize; export const requirePin = async ({ body, user }) => { - if (user && user.pin && user.pin !== body.pin) + if (!user || (user.pin && user.pin !== body.pin)) throw new Error("Invalid pin"); }; diff --git a/routes/users.js b/routes/users.js index b142eb3a..c8a9a810 100644 --- a/routes/users.js +++ b/routes/users.js @@ -21,6 +21,7 @@ import bc from "$lib/bitcoin"; import lq from "$lib/liquid"; import { emit } from "$lib/sockets"; import register from "$lib/register"; +import { requirePin } from "$lib/utils"; const pick = (O, ...K) => K.reduce((o, k) => ((o[k] = O[k]), o), {}); @@ -180,7 +181,6 @@ app.post("/user", auth, async (req, res) => { user.email = email; user.address = address; - if (password && password === confirm) { user.password = await bcrypt.hash(password, 1); } @@ -646,3 +646,13 @@ app.post("/signMessage", auth, async function(req, res) { res.code(500).send("Address not found for user"); }); + +app.post("/otpsecret", auth, async function(req, res) { + try { + await requirePin(req); + let { otpsecret } = req.user; + res.send({ secret: otpsecret }); + } catch (e) { + res.code(500).send(e.message); + } +}); -- cgit v1.2.3