From 683582ea8c255573fdf034443f2eabf3c32f1e50 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 2 Oct 2025 11:44:49 -0700 Subject: [PATCH] Fix: Add missing auth-params endpoint for login --- functions/api/auth-params.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 functions/api/auth-params.js diff --git a/functions/api/auth-params.js b/functions/api/auth-params.js new file mode 100644 index 0000000..39fdde5 --- /dev/null +++ b/functions/api/auth-params.js @@ -0,0 +1,21 @@ +const json = (d, o) => new Response(JSON.stringify(d), { ...o, headers: { 'Content-Type': 'application/json' } }); + +export async function onRequestGet({ request, env }) { + try { + const u = new URL(request.url).searchParams.get('username'); + if (!u) return json({ error: 'Missing username' }, { status: 400 }); + + const pass_hash = await env.D1_SPCHCAP.prepare('SELECT pass_hash FROM users WHERE username = ?').bind(u).first('pass_hash'); + if (!pass_hash) return json({ error: 'User not found' }, { status: 404 }); + + const parts = pass_hash.split('$'); + if (parts.length !== 6 || parts[0] !== 'scrypt') { + return json({ error: 'Invalid hash format' }, { status: 500 }); + } + + const [_, N, r, p, salt_b64] = parts; + return json({ N: +N, r: +r, p: +p, salt_b64 }); + } catch (e) { + return json({ error: { message: e.message } }, { status: 500 }); + } +}