mirror of
https://github.com/spchcap/speech.capital.git
synced 2026-01-13 16:18:06 +00:00
Fix: Add missing auth-params endpoint for login
This commit is contained in:
21
functions/api/auth-params.js
Normal file
21
functions/api/auth-params.js
Normal 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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user