Improve user group assignment debugging and logging in production

Add SQL debugging script and enhanced console logs to diagnose user group assignment issues in production, addressing user reports of unassigned groups.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: a8a78c07-e900-425c-a577-5b4c5894379d
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/a8a78c07-e900-425c-a577-5b4c5894379d/fwSlq3W
This commit is contained in:
michaelschal committed 2025-08-11 19:53:26 +00:00
1 parent f705fb4b1c
commit 07b848b127
4 files changed
+74 -1

No files matched your search

+13 -1
View File
@@ -187,12 +187,18 @@ export class DatabaseStorage implements IStorage {
}
async getUserWithGroups(id: string): Promise<UserWithGroups | undefined> {
console.log(`🔍 getUserWithGroups called for user: ${id}`);
// Get the user first
const user = await this.getUser(id);
if (!user) return undefined;
if (!user) {
console.log(`❌ User ${id} not found`);
return undefined;
}
// Fixed: Use manual SQL to avoid userGroups.createdAt column that doesn't exist
try {
console.log(`🔍 Querying user_groups for user: ${id}`);
const result = await db.execute(sql`
SELECT
ug.user_id,
@@ -211,6 +217,9 @@ export class DatabaseStorage implements IStorage {
WHERE ug.user_id = ${id}
`);
console.log(`🔍 Found ${result.rows.length} group assignments for user ${id}`);
console.log(`🔍 Raw query result:`, result.rows);
const userGroupsData = result.rows.map((row: any) => ({
userId: row.user_id,
groupId: row.group_id,
@@ -228,12 +237,15 @@ export class DatabaseStorage implements IStorage {
}
}));
console.log(`✅ Processed ${userGroupsData.length} groups for user ${id}`);
return {
...user,
userGroups: userGroupsData,
};
} catch (error) {
console.error('❌ getUserWithGroups error:', error);
console.error('❌ Error details:', error?.code, error?.message);
// Fallback: return user with empty groups
return {
...user,