aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/invoices.ts1
-rw-r--r--routes/users.ts35
2 files changed, 21 insertions, 15 deletions
diff --git a/lib/invoices.ts b/lib/invoices.ts
index d79ead69..0a94334c 100644
--- a/lib/invoices.ts
+++ b/lib/invoices.ts
@@ -39,6 +39,7 @@ export const generate = async ({ invoice, user }) => {
let account = await g(`account:${aid}`);
if (!account) account = await g(`account:${user.id}`);
if (!account) fail("account not found");
+ aid = account.id;
const rates = await g("rates");
if (!currency) currency = user.currency;
diff --git a/routes/users.ts b/routes/users.ts
index c1cce6e7..3381af83 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -183,22 +183,27 @@ export default {
},
async enable2fa(req, res) {
- const {
- user,
- body: { token },
- } = req;
- const { id, otpsecret, username } = user;
- const isValid = authenticator.check(token, otpsecret);
- if (isValid) {
- user.twofa = true;
- await s(`user:${id}`, user);
- emit(username, "user", user);
- } else {
- return res.code(500).send("Invalid token");
- }
+ try {
+ const {
+ user,
+ body: { token },
+ } = req;
+ const { id, otpsecret, username } = user;
+ const isValid = authenticator.check(token, otpsecret);
+ if (isValid) {
+ user.twofa = true;
+ await s(`user:${id}`, user);
+ emit(username, "user", user);
+ } else {
+ return res.code(500).send("Invalid token");
+ }
- l("enabled 2fa", username);
- res.send({});
+ l("enabled 2fa", username);
+ res.send({});
+ } catch (e) {
+ console.log(e);
+ bail(res, e.message);
+ }
},
async update(req, res) {