aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/users.ts7
1 files changed, 5 insertions, 2 deletions
diff --git a/routes/users.ts b/routes/users.ts
index cfa41b8b..51eb14be 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -412,10 +412,10 @@ export default {
const existingUsername = exists?.username
?.toLowerCase()
.replace(/\s/g, "");
+ const takeAnon = exists && un !== existingUsername && exists.anon;
if (exists && un !== existingUsername) {
warn("key in use", pubkey, username, existingUsername);
- if (exists.anon) await db.del(`user:${pubkey}`);
- else fail("Key in use by another account");
+ if (!exists.anon) fail("Key in use by another account");
}
const event = JSON.parse(body.event);
@@ -433,6 +433,9 @@ export default {
pubkey = pubkey.replace(/\s*/g, "");
if (pubkey.length !== 64) fail(`Invalid pubkey ${pubkey}`);
+ // Only unlink an anon account's key once the caller has proven they
+ // hold it (signed challenge above).
+ if (takeAnon) await db.del(`user:${pubkey}`);
await db.del(`user:${user.pubkey}`);
user.pubkey = pubkey;
user.nsec = undefined;