From 4a5ea663b6ab93a0be05569b061462e112e3001c Mon Sep 17 00:00:00 2001 From: Deep Koluguri Date: Wed, 3 Jun 2026 01:16:12 -0400 Subject: [PATCH] fix: seed demo users for doctor and pharmacy to fix 401 on login --- backend/db.js | 22 ++++++++++++++++++++++ login.html | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/db.js b/backend/db.js index 05e0870..c73bd1c 100644 --- a/backend/db.js +++ b/backend/db.js @@ -134,6 +134,27 @@ async function seedSuperAdmin() { console.log(`[DB] Super admin seeded: ${email}`); } +async function seedDemoUsers() { + const defaultPassword = 'password'; + const hash = await bcrypt.hash(defaultPassword, 10); + const demoUsers = [ + { email: 'doctor@curio.app', name: 'Dr. Sharma', role: 'DOCTOR', tenant_id: 'default' }, + { email: 'pharmacy@curio.app', name: 'Pharmacist', role: 'PHARMACIST', tenant_id: 'default' }, + ]; + + for (const u of demoUsers) { + const existing = await pool.query('SELECT id FROM users WHERE email = $1', [u.email]); + if (existing.rows.length === 0) { + await pool.query( + `INSERT INTO users (tenant_id, email, password_hash, name, role) + VALUES ($1, $2, $3, $4, $5)`, + [u.tenant_id, u.email, hash, u.name, u.role] + ); + console.log(`[DB] Demo user seeded: ${u.email}`); + } + } +} + // ── Seed legacy in-memory tenants into DB ───────────────────────────────────── async function seedLegacyTenants() { @@ -192,6 +213,7 @@ async function initSchema() { console.log('[DB] Schema ready.'); await seedSuperAdmin(); await seedLegacyTenants(); + await seedDemoUsers(); } catch (err) { console.error('[DB] Schema init failed:', err.message); // Don't crash — let server start even if DB is temporarily unavailable diff --git a/login.html b/login.html index 24039e8..20fa141 100644 --- a/login.html +++ b/login.html @@ -41,7 +41,9 @@