From daad542527afc68ceb39cd8c76f7f6b680d32f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Thu, 5 Mar 2026 16:25:32 -0300 Subject: [PATCH] fix: resolve super_admin auto-provisioning timing issue on fresh stacks --- backend/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/index.js b/backend/index.js index dbeac0e..c227afb 100644 --- a/backend/index.js +++ b/backend/index.js @@ -609,7 +609,7 @@ if (process.env.NODE_ENV === 'production') { } // Auto-provision Super Admin -const provisionSuperAdmin = async (retries = 5, delay = 5000) => { +const provisionSuperAdmin = async (retries = 10, delay = 10000) => { const email = 'suporte@blyzer.com.br'; for (let i = 0; i < retries; i++) { @@ -636,12 +636,15 @@ const provisionSuperAdmin = async (retries = 5, delay = 5000) => { } const token = crypto.randomBytes(32).toString('hex'); + // Delete any old unused tokens for this email to prevent buildup + await pool.query('DELETE FROM password_resets WHERE email = ?', [email]); + await pool.query( 'INSERT INTO password_resets (email, token, expires_at) VALUES (?, ?, DATE_ADD(NOW(), INTERVAL 15 MINUTE))', [email, token] ); - const setupLink = `${process.env.APP_URL || 'http://localhost:3001'}/#/reset-password?token=${token}`; + const setupLink = `${process.env.APP_URL || 'http://localhost:3001'}/#/setup-account?token=${token}`; console.log(`\n\n=== SUPER ADMIN SETUP LINK ===\n${setupLink}\n==============================\n\n`); await transporter.sendMail({