From 8076d860c7b9895bed874a9b1f62152e6d78367b Mon Sep 17 00:00:00 2001 From: Dorian Date: Fri, 13 Mar 2026 22:28:43 +0000 Subject: [PATCH] fix: creator auto-creates as bot (poll mode), auto-upgrade existing human records The creator was being registered with webhookUrl='http://human.local/' and isHuman=true. Now uses poll.local and isHuman=false. The auto-upgrade logic on login also converts any existing creator record from human to bot mode. Co-Authored-By: Claude Opus 4.6 --- server/src/routes/auth.ts | 45 +++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index f22a3e0..6096423 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -53,14 +53,14 @@ authRouter.post('/login', rateLimit(60_000, 10), async (c) => { }).from(schema.bots).where(eq(schema.bots.publicKey, pubkey)).limit(1) if (rows.length === 0) { - // Auto-create human fighter for the Creator if not registered + // Auto-create bot for the Creator if not registered if (isCreatorPubkey(pubkey)) { const id = nanoid(12) const secret = randomBytes(32).toString('hex') await db.insert(schema.bots).values({ id, name: 'the_creator', - webhookUrl: 'http://human.local/', + webhookUrl: 'http://poll.local/', avatarSeed: 'the_creator', archetype: 'the_creator', secretHash: createHash('sha256').update(secret).digest('hex'), @@ -84,7 +84,7 @@ authRouter.post('/login', rateLimit(60_000, 10), async (c) => { bestStreak: 0, tier: 0, isActive: true, - isHuman: true, + isHuman: false, customization: null, satsWon: 0, satsWagered: 0, @@ -96,14 +96,21 @@ authRouter.post('/login', rateLimit(60_000, 10), async (c) => { } const bot = rows[0] - const isHuman = bot.webhookUrl === 'http://human.local/' - // Auto-upgrade: if creator logs in, ensure archetype is always the_creator - if (isCreatorPubkey(pubkey) && bot.archetype !== "the_creator") { - await db.update(schema.bots).set({ archetype: "the_creator" }).where(eq(schema.bots.id, bot.id)) - bot.archetype = "the_creator" + // Auto-upgrade: if creator logs in, ensure archetype + bot mode are correct + if (isCreatorPubkey(pubkey)) { + const fixes: Record = {} + if (bot.archetype !== "the_creator") fixes.archetype = "the_creator" + if (bot.webhookUrl === "http://human.local/") fixes.webhookUrl = "http://poll.local/" + if (Object.keys(fixes).length > 0) { + await db.update(schema.bots).set(fixes).where(eq(schema.bots.id, bot.id)) + if (fixes.archetype) bot.archetype = "the_creator" + if (fixes.webhookUrl) bot.webhookUrl = "http://poll.local/" + } } + const isHuman = bot.webhookUrl === 'http://human.local/' + return c.json({ exists: true, bot: { @@ -411,14 +418,20 @@ authRouter.post('/nostr/session', rateLimit(60_000, 10), async (c) => { if (rows.length > 0) { const bot = rows[0] botId = bot.id - const isHuman = bot.webhookUrl === 'http://human.local/' - - // Auto-upgrade creator archetype - if (isCreatorPubkey(pubkey) && bot.archetype !== "the_creator") { - await db.update(schema.bots).set({ archetype: "the_creator" }).where(eq(schema.bots.id, bot.id)) - bot.archetype = "the_creator" + // Auto-upgrade: if creator logs in, ensure archetype + bot mode are correct + if (isCreatorPubkey(pubkey)) { + const fixes: Record = {} + if (bot.archetype !== "the_creator") fixes.archetype = "the_creator" + if (bot.webhookUrl === "http://human.local/") fixes.webhookUrl = "http://poll.local/" + if (Object.keys(fixes).length > 0) { + await db.update(schema.bots).set(fixes).where(eq(schema.bots.id, bot.id)) + if (fixes.archetype) bot.archetype = "the_creator" + if (fixes.webhookUrl) bot.webhookUrl = "http://poll.local/" + } } + const isHuman = bot.webhookUrl === 'http://human.local/' + botData = { id: bot.id, name: bot.name, @@ -445,7 +458,7 @@ authRouter.post('/nostr/session', rateLimit(60_000, 10), async (c) => { await db.insert(schema.bots).values({ id, name: 'the_creator', - webhookUrl: 'http://human.local/', + webhookUrl: 'http://poll.local/', avatarSeed: 'the_creator', archetype: 'the_creator', secretHash: createHash('sha256').update(secret).digest('hex'), @@ -468,7 +481,7 @@ authRouter.post('/nostr/session', rateLimit(60_000, 10), async (c) => { bestStreak: 0, tier: 0, isActive: true, - isHuman: true, + isHuman: false, customization: null, satsWon: 0, satsWagered: 0,