diff options
| author | Adam Soltys <[email protected]> | 2022-11-08 02:36:12 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-11-08 02:36:12 -0800 |
| commit | 9b060ad4e907bf2a69d787e4a939ea30df0a3eb2 (patch) | |
| tree | d8fdcde30fde3438a26bfc1a9026862e1ce9adfa | |
| parent | c2c183d5ac76813fd4f961baabb17ca7bb316926 (diff) | |
| download | coinos-server-9b060ad4e907bf2a69d787e4a939ea30df0a3eb2.tar.gz coinos-server-9b060ad4e907bf2a69d787e4a939ea30df0a3eb2.zip | |
otpsecret endpoint
| -rw-r--r-- | lib/utils.js | 2 | ||||
| -rw-r--r-- | 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); + } +}); |
