From 7f1101b919e19e3b3481e688b3ca24da69437cab Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Sun, 28 Sep 2025 10:41:22 -0700 Subject: [PATCH] Feat: Add user signup API endpoint --- functions/api/signup.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 functions/api/signup.js diff --git a/functions/api/signup.js b/functions/api/signup.js new file mode 100644 index 0000000..3952218 --- /dev/null +++ b/functions/api/signup.js @@ -0,0 +1,11 @@ +export async function onRequestPost({ request, env }) { + try { + const { username, pass_hash } = await request.json(); + if (!username || !pass_hash) return new Response('Missing fields', { status: 400 }); + if (await env.D1_EV.prepare("SELECT 1 FROM users WHERE username = ?").bind(username).first()) + return new Response('User already exists', { status: 409 }); + await env.D1_EV.prepare("INSERT INTO users (username, pass_hash) VALUES (?, ?)") + .bind(username, pass_hash).run(); + return Response.json({ success: true }, { status: 201 }); + } catch (e) { return new Response(e.message, { status: 500 }); } +}