aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-08-05 10:49:56 -0700
committerAdam Soltys <[email protected]>2020-08-05 10:49:56 -0700
commit2717860daf920b14eaa6859832de8ba26f239d06 (patch)
treef94402c5004d576b4bc2560e991f89c28cf0c76f
parent1ac57d2081cf05b82ad0e9982e4b3a013f43a961 (diff)
downloadcoinos-server-2717860daf920b14eaa6859832de8ba26f239d06.tar.gz
coinos-server-2717860daf920b14eaa6859832de8ba26f239d06.zip
logout optional auth
-rw-r--r--routes/users.js48
1 files changed, 26 insertions, 22 deletions
diff --git a/routes/users.js b/routes/users.js
index 99dd6046..75c48e62 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -273,22 +273,26 @@ app.post(
app.post(
"/logout",
- auth,
+ optionalAuth,
ah(async (req, res) => {
let { subscription } = req.body;
- const { username } = req.user;
- l.info("logging out", username);
if (!subscription) return res.end();
- let i = req.user.subscriptions.findIndex(
- (s) => JSON.stringify(s) === subscription
- );
- if (i > -1) {
- req.user.subscriptions.splice(i, 1);
+
+ const { username } = req.user;
+
+ if (username) {
+ l.info("logging out", username);
+ let i = req.user.subscriptions.findIndex(
+ (s) => JSON.stringify(s) === subscription
+ );
+ if (i > -1) {
+ req.user.subscriptions.splice(i, 1);
+ }
+ await req.user.save();
+ Object.keys(logins).map(
+ (k) => logins[k]["username"] === username && delete logins[k]
+ );
}
- await req.user.save();
- Object.keys(logins).map(
- (k) => logins[k]["username"] === username && delete logins[k]
- );
res.end();
})
@@ -300,22 +304,22 @@ app.get(
const { network, type } = req.query;
let address;
- if (network === 'bitcoin') {
- if (!config.bitcoin) return res.status(500).send("Bitcoin not configured");
+ if (network === "bitcoin") {
+ if (!config.bitcoin)
+ return res.status(500).send("Bitcoin not configured");
- if (config.bitcoin.walletpass)
- await bc.walletPassphrase(config.bitcoin.walletpass, 300);
+ if (config.bitcoin.walletpass)
+ await bc.walletPassphrase(config.bitcoin.walletpass, 300);
address = await bc.getNewAddress("", type || "bech32");
- } else if (network === 'liquid') {
-
- if (!config.liquid) return res.status(500).send("Liquid not configured");
+ } else if (network === "liquid") {
+ if (!config.liquid) return res.status(500).send("Liquid not configured");
- if (config.liquid.walletpass)
- await lq.walletPassphrase(config.liquid.walletpass, 300);
+ if (config.liquid.walletpass)
+ await lq.walletPassphrase(config.liquid.walletpass, 300);
address = await lq.getNewAddress("", type || "bech32");
- }
+ }
res.send(address);
})