aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-06-25 20:29:14 -0700
committerAdam Soltys <[email protected]>2020-06-25 20:29:30 -0700
commit96dff083b35748e65d728c4958d5426e8e13f6c8 (patch)
treecf4fcfdaa4c2a10678812cc3ddff41b0927e8616 /routes
parent661eafded5cffe1cc74a907e6cfe629895e35b98 (diff)
downloadcoinos-server-96dff083b35748e65d728c4958d5426e8e13f6c8.tar.gz
coinos-server-96dff083b35748e65d728c4958d5426e8e13f6c8.zip
authorize additional linking keys
Diffstat (limited to 'routes')
-rw-r--r--routes/lnurl.js14
-rw-r--r--routes/users.js8
2 files changed, 18 insertions, 4 deletions
diff --git a/routes/lnurl.js b/routes/lnurl.js
index b89f52a2..7cd1a19e 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -6,13 +6,19 @@ logins = {};
lnurlServer = lnurl.createServer(config.lnurl);
-app.get("/loginUrl", async (req, res) => {
+var optionalAuth = function(req, res, next) {
+ passport.authenticate('jwt', { session: false }, function(err, user, info) {
+ req.user = user;
+ next();
+ })(req, res, next);
+};
+
+app.get("/loginUrl", optionalAuth, async (req, res) => {
try {
const result = await lnurlServer.generateNewUrl("login");
- const { username } = req.query;
- if (username !== "undefined") {
- logins[result.secret] = username;
+ if (req.user) {
+ logins[result.secret] = req.user.username;
}
res.send(result);
diff --git a/routes/users.js b/routes/users.js
index 522d2e6a..5a708d00 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -262,6 +262,14 @@ app.post("/keys", auth, async (req, res) => {
emit(req.user.username, "key", key);
});
+app.post("/keys/delete", auth, async (req, res) => {
+ const { hex } = req.body;
+ (await db.Key.findOne({ where: {
+ user_id: req.user.id,
+ hex
+ }})).destroy();
+});
+
app.post("/login", async (req, res) => {
const {
params,