aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-02-23 21:03:54 -0800
committerAdam Soltys <[email protected]>2024-02-23 21:03:54 -0800
commitd5d15b1a9f89e7cf621faf96d11e2fd139037a54 (patch)
treed4e978decb423dcf3fa9b0985c8f5189e18adb7f
parent0af4df3e3dea05063fe392a06772771ea79483a4 (diff)
downloadcoinos-server-d5d15b1a9f89e7cf621faf96d11e2fd139037a54.tar.gz
coinos-server-d5d15b1a9f89e7cf621faf96d11e2fd139037a54.zip
admin endpoints
-rw-r--r--index.js5
-rw-r--r--lib/auth.js11
-rw-r--r--routes/users.js14
3 files changed, 29 insertions, 1 deletions
diff --git a/index.js b/index.js
index 0564ea9e..cd5781ae 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,5 @@
import app from "$lib/app";
-import { auth, optional } from "$lib/auth";
+import { auth, admin, optional } from "$lib/auth";
import { fillPool } from "$lib/nostr";
import { listenForLightning } from "$lib/lightning";
@@ -113,6 +113,9 @@ app.post("/requests/delete", auth, requests.destroy);
app.post("/shopify/:id", shopify);
+app.post("/hidepay", admin, users.hidepay);
+ app.post("/unlimit", admin, users.unlimit);
+
let host = process.env.HOST || "0.0.0.0";
let port = process.env.PORT || 3119;
diff --git a/lib/auth.js b/lib/auth.js
index 944cc3b2..0a8d43d3 100644
--- a/lib/auth.js
+++ b/lib/auth.js
@@ -4,6 +4,17 @@ import { fail, getUser } from "$lib/utils";
import config from "$config";
import jwt from "passport-jwt";
+export const admin = {
+ preValidation: fastifyPassport.authenticate(
+ "jwt",
+ { session: false },
+ function (req, res, err, user, info) {
+ if (!user.admin) return res.code(401).send("unauthorized");
+ req.user = user;
+ },
+ ),
+};
+
export const optional = {
preValidation: fastifyPassport.authenticate(
"jwt",
diff --git a/routes/users.js b/routes/users.js
index 59de22b2..df16c75e 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -532,4 +532,18 @@ export default {
let item = await g(`item:${id}`);
return item;
},
+
+ async hidepay({ body: { username } }, res) {
+ let u = await getUser(username);
+ u.hidepay = true;
+ await s(`user:${u.id}`, u);
+ res.send({});
+ },
+
+ async unlimit({ body: { username } }, res) {
+ let u = await getUser(username);
+ u.unlimited = true;
+ await s(`user:${u.id}`, u);
+ res.send({});
+ },
};