aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-02-11 13:40:05 -0800
committerAdam Soltys <[email protected]>2025-02-11 13:40:05 -0800
commitde7435e34580e1a9b4b8d95b2a5013112414098f (patch)
tree97074cadf3a63512c2c5f554a3083924fd046b74 /routes
parent8add46c0975686ce0967c2c38514a31aad6ee8cb (diff)
downloadcoinos-server-de7435e34580e1a9b4b8d95b2a5013112414098f.tar.gz
coinos-server-de7435e34580e1a9b4b8d95b2a5013112414098f.zip
default app on register
Diffstat (limited to 'routes')
-rw-r--r--routes/nostr.ts9
-rw-r--r--routes/users.ts12
2 files changed, 8 insertions, 13 deletions
diff --git a/routes/nostr.ts b/routes/nostr.ts
index 5000ccc7..9c61bf16 100644
--- a/routes/nostr.ts
+++ b/routes/nostr.ts
@@ -8,6 +8,7 @@ import {
getNostrUser,
getProfile,
pool,
+ publish,
q,
serverPubkey,
} from "$lib/nostr";
@@ -16,7 +17,6 @@ import { scan } from "$lib/strfry";
import { bail, fail, fields, getUser } from "$lib/utils";
import got from "got";
import type { Event } from "nostr-tools";
-import { verifyEvent } from "nostr-tools";
import { decode } from "nostr-tools/nip19";
import type { ProfilePointer } from "nostr-tools/nip19";
import { getZapEndpoint, makeZapRequest } from "nostr-tools/nip57";
@@ -207,10 +207,8 @@ export default {
try {
const { event } = req.body;
const { pubkey } = req.user;
- // const { write: relays } = await getRelays(pubkey);
- // if (!relays.includes(config.nostr)) relays.push(config.nostr);
- if (!verifyEvent(event)) fail("Invalid event");
- await load(JSON.stringify(event));
+
+ await publish(event);
if (event.kind === 3) {
db.del(`${pubkey}:follows`);
@@ -219,6 +217,7 @@ export default {
res.send({});
} catch (e) {
+ console.log(e);
bail(res, e.message);
}
},
diff --git a/routes/users.ts b/routes/users.ts
index c0d99b7d..9f5905bf 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -179,16 +179,12 @@ export default {
else fail("Key in use by another account");
}
- const { challenge } = body;
const event = JSON.parse(body.event);
+ const challenge = event.tags.find((t) => t[0] === "challenge")[1];
const c = await g(`challenge:${challenge}`);
- if (!c) fail("Invalid or expired login challenge");
+ if (!c) fail("Invalid or expired challenge");
- if (
- !verifyEvent(event) ||
- event.content !== challenge ||
- event.pubkey !== pubkey
- )
+ if (!verifyEvent(event) || event.pubkey !== pubkey)
fail("Invalid signature or challenge mismatch.");
pubkey = pubkey.replace(/\s*/g, "");
@@ -332,7 +328,7 @@ export default {
res.send({ challenge: id });
},
- async nostrLogin(req, res) {
+ async nostrAuth(req, res) {
try {
const { event, challenge, twofa } = req.body;
const ip = req.headers["cf-connecting-ip"];