From 1921316e03edd3889bae54b3b349783d27e5e6f3 Mon Sep 17 00:00:00 2001 From: ghaddaditw <40211818-ghaddaditw@users.noreply.replit.com> Date: Sun, 8 Jun 2025 08:11:27 +0000 Subject: [PATCH] Add initial admin account creation functionality for project setup Implements a POST route '/api/admin/setup' to create the initial admin user. Replit-Commit-Author: Agent Replit-Commit-Session-Id: c5f0c281-8dd8-4846-b452-4a07bcd21062 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9777c70b-fc38-4831-8d6b-78dfffe041b0/6dcb6ab3-b230-4a8d-b7c0-1a50c9073254.jpg --- server/routes.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/server/routes.ts b/server/routes.ts index b3c8e7c..0b0ad71 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -83,6 +83,41 @@ export async function registerRoutes(app: Express): Promise { app.use(performanceOptimizationService.performanceMiddleware); app.use(generalRateLimit); + // Admin setup endpoint (one-time use) + app.post('/api/admin/setup', async (req: Request, res: Response) => { + try { + // Check if any admin users already exist + const existingAdmin = await storage.getUserByEmail('admin@menassist.com'); + if (existingAdmin) { + return res.status(400).json({ error: 'Admin already exists' }); + } + + const hashedPassword = await bcryptjs.hash('MenAssist2025!', 10); + const adminUser = await storage.createUser({ + username: 'admin', + email: 'admin@menassist.com', + password: hashedPassword, + role: 'admin', + firstName: 'Admin', + lastName: 'User', + onboardingComplete: true, + voiceEnabled: true, + notificationsEnabled: true + }); + + res.json({ + message: 'Admin user created successfully', + credentials: { + email: 'admin@menassist.com', + password: 'MenAssist2025!' + } + }); + } catch (error) { + console.error('Admin setup error:', error); + res.status(500).json({ error: 'Failed to create admin user' }); + } + }); + // Health check endpoint for production monitoring app.get('/health', async (req, res) => { const health = await monitoringService.getHealthCheck();