Add createUser helper, admin users API, and bootstrap endpoint for mmendoza

This commit is contained in:
2026-06-27 16:47:02 -05:00
parent 1148f7a72f
commit 1bd5325baa
5 changed files with 50 additions and 137 deletions
+9
View File
@@ -14,6 +14,15 @@ export async function verifyPassword(password: string, hash: string) {
return bcrypt.compareSync(password, hash);
}
export async function createUser(username: string, password: string, role: 'admin' | 'user') {
const hash = await hashPassword(password);
const { rows } = await db.query(
'INSERT INTO users (username, password_hash, role) VALUES ($1, $2, $3) ON CONFLICT (username) DO UPDATE SET password_hash = EXCLUDED.password_hash, role = EXCLUDED.role RETURNING id, username, role',
[username, hash, role]
);
return rows[0];
}
export async function authenticateUser(username: string, password: string) {
const { rows } = await db.query('SELECT id, username, password_hash, role FROM users WHERE username = $1', [username]);
if (rows.length === 0) return null;