fix(seeder): seed 'superadmin' hash at runtime alongside 'lol'
Migration 010 creates 'superadmin' with placeholder hash '$invalid-placeholder-run-seeder$', leaving it unable to log in. The seeder now upserts 'superadmin' with the same bcrypt(pass+pepper) hash as 'lol', ensuring both identifiers work after every seed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e5e43974a5
commit
6b1c058e8e
1 changed files with 18 additions and 0 deletions
|
|
@ -42,6 +42,24 @@ export async function seedUsers() {
|
||||||
`, [superAdminId]);
|
`, [superAdminId]);
|
||||||
console.log(' ✓ SuperAdmin seeded: lol (hash gerado com pepper do ambiente)');
|
console.log(' ✓ SuperAdmin seeded: lol (hash gerado com pepper do ambiente)');
|
||||||
|
|
||||||
|
// 0b. Seed superadmin alias — migration 010 cria este usuário com hash placeholder.
|
||||||
|
// O seeder define o hash correto aqui para garantir que o login funcione.
|
||||||
|
// Mesmo hash e senha que lol: Admin@2025! + pepper
|
||||||
|
await pool.query(`
|
||||||
|
INSERT INTO users (identifier, password_hash, role, full_name, email, name, status, active)
|
||||||
|
VALUES ('superadmin', $1, 'superadmin', 'Super Administrator', 'admin@gohorsejobs.com', 'Super Administrator', 'active', true)
|
||||||
|
ON CONFLICT (identifier) DO UPDATE SET
|
||||||
|
password_hash = EXCLUDED.password_hash,
|
||||||
|
status = 'active',
|
||||||
|
updated_at = NOW()
|
||||||
|
`, [superAdminHash]);
|
||||||
|
await pool.query(`
|
||||||
|
INSERT INTO user_roles (user_id, role)
|
||||||
|
SELECT id, 'superadmin' FROM users WHERE identifier = 'superadmin'
|
||||||
|
ON CONFLICT (user_id, role) DO NOTHING
|
||||||
|
`);
|
||||||
|
console.log(' ✓ SuperAdmin seeded: superadmin (mesmo hash que lol)');
|
||||||
|
|
||||||
// 1. Create Company Admins
|
// 1. Create Company Admins
|
||||||
const admins = [
|
const admins = [
|
||||||
{ identifier: 'takeshi_yamamoto', fullName: 'Takeshi Yamamoto', company: 'TechCorp', email: 'takeshi@techcorp.com', pass: 'Takeshi@2025', roles: ['admin'] },
|
{ identifier: 'takeshi_yamamoto', fullName: 'Takeshi Yamamoto', company: 'TechCorp', email: 'takeshi@techcorp.com', pass: 'Takeshi@2025', roles: ['admin'] },
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue