Feat: Add user signin API endpoint

This commit is contained in:
2025-09-28 10:41:24 -07:00
parent 7f1101b919
commit 6db5c1b657

9
functions/api/signin.js Normal file
View File

@@ -0,0 +1,9 @@
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 });
const user = await env.D1_EV.prepare("SELECT pass_hash FROM users WHERE username = ?").bind(username).first();
if (user?.pass_hash !== pass_hash) return new Response('Invalid credentials', { status: 401 });
return Response.json({ success: true });
} catch (e) { return new Response(e.message, { status: 500 }); }
}