mirror of
https://github.com/4ev-link/4ev.link.git
synced 2026-01-14 16:48:41 +00:00
Feat: Add user signin API endpoint
This commit is contained in:
9
functions/api/signin.js
Normal file
9
functions/api/signin.js
Normal 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 }); }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user