Fix error handling in nameRequestController

This commit is contained in:
Alex Gleason 2025-02-21 20:33:44 -06:00
parent 5fec5deb06
commit 8437da1200
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -84,7 +84,13 @@ export const nameRequestController: AppController = async (c) => {
const pubkey = await signer.getPublicKey(); const pubkey = await signer.getPublicKey();
const { conf } = c.var; const { conf } = c.var;
const { name, reason } = nameRequestSchema.parse(await c.req.json()); const result = nameRequestSchema.safeParse(await c.req.json());
if (!result.success) {
return c.json({ error: 'Invalid username', schema: result.error }, 400);
}
const { name, reason } = result.data;
const [existing] = await store.query([{ kinds: [3036], authors: [pubkey], '#r': [name], limit: 1 }]); const [existing] = await store.query([{ kinds: [3036], authors: [pubkey], '#r': [name], limit: 1 }]);
if (existing) { if (existing) {