Ensure the admin user always has full access to manage the application

Fixes admin role assignment, adds SQL scripts for manual correction, and provides debugging tools for production issues.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 4b008663-bd72-492b-b0b6-fa252367e730
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/4b008663-bd72-492b-b0b6-fa252367e730/nHdBv6m
This commit is contained in:
michaelschal committed 2025-07-19 15:50:22 +00:00
1 parent a1ff814f6b
commit 87722d8132
6 files changed
+180

No files matched your search

+11
View File
@@ -331,6 +331,17 @@ export class DatabaseStorage implements IStorage {
async initializeDefaults(): Promise<{ defaultAdminCredentials?: { username: string; password: string } }> {
const existingUsers = await this.getAllUsers();
// FORCE ADMIN ROLE CORRECTION - Production fix
const adminUsers = existingUsers.filter(u => u.username === 'admin');
for (const adminUser of adminUsers) {
if (adminUser.role !== 'administrator') {
console.log(`🔧 FIXING ADMIN ROLE: User ID ${adminUser.id} role "${adminUser.role}" -> "administrator"`);
await db.update(users)
.set({ role: 'administrator' })
.where(eq(users.id, adminUser.id));
}
}
if (existingUsers.length === 0) {
// Create default store
const defaultStore = await this.createStore({