Fix: Add missing auth-params endpoint for login

This commit is contained in:
2025-10-02 11:44:49 -07:00
parent acc739ddb7
commit 683582ea8c

View File

@@ -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 });
}
}