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
This commit is contained in:
ghaddaditw
2025-06-08 08:11:27 +00:00
parent 9285a00cd3
commit 1921316e03
+35
View File
@@ -83,6 +83,41 @@ export async function registerRoutes(app: Express): Promise<Server> {
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();