Fix iOS Safari auth loops and simplify admin dashboard
All checks were successful
Build And Push Image / docker (push) Successful in 3m4s
All checks were successful
Build And Push Image / docker (push) Successful in 3m4s
- Add session check throttling in useAuth to prevent iOS Safari authentication loops - Simplify admin dashboard by removing complex system metrics and stats - Remove system-metrics utility and streamline stats API endpoint - Update admin interface to focus on core user and role management
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
console.log('📊 Admin stats requested at:', new Date().toISOString());
|
||||
console.log('📊 Simple admin stats requested at:', new Date().toISOString());
|
||||
|
||||
try {
|
||||
// Check if user is admin (middleware should handle this, but double-check)
|
||||
// Check if user is admin
|
||||
const sessionManager = createSessionManager();
|
||||
const cookieHeader = getHeader(event, 'cookie');
|
||||
const session = sessionManager.getSession(cookieHeader);
|
||||
@@ -17,78 +17,17 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
console.log('✅ Admin access verified for user:', session.user.email);
|
||||
|
||||
// Get real system metrics
|
||||
const { getSystemMetrics, getSystemHealthStatus, formatBytes } = await import('~/server/utils/system-metrics');
|
||||
const systemMetrics = await getSystemMetrics();
|
||||
const systemHealth = getSystemHealthStatus(systemMetrics);
|
||||
|
||||
// Build comprehensive stats with real data
|
||||
// Return simple user-focused stats without system metrics
|
||||
const stats = {
|
||||
// Real system metrics
|
||||
totalUsers: 156, // TODO: Get from Keycloak API
|
||||
activeUsers: 45, // TODO: Get from session store
|
||||
totalSessions: 67, // TODO: Get from session store
|
||||
systemHealth,
|
||||
lastBackup: new Date().toISOString(),
|
||||
diskUsage: `${systemMetrics.disk.usagePercent}%`,
|
||||
memoryUsage: `${systemMetrics.memory.usagePercent}%`,
|
||||
// Simple user count (mock data for now - would come from Keycloak API)
|
||||
userCount: 25,
|
||||
|
||||
// Enhanced system metrics with real data
|
||||
systemMetrics: {
|
||||
cpu: systemMetrics.cpu.usage,
|
||||
memory: systemMetrics.memory.usagePercent,
|
||||
disk: systemMetrics.disk.usagePercent,
|
||||
uptime: systemMetrics.uptime,
|
||||
processes: systemMetrics.processes.total,
|
||||
cpuCores: systemMetrics.cpu.cores,
|
||||
cpuModel: systemMetrics.cpu.model,
|
||||
memoryTotal: formatBytes(systemMetrics.memory.total),
|
||||
memoryUsed: formatBytes(systemMetrics.memory.used),
|
||||
diskTotal: formatBytes(systemMetrics.disk.total),
|
||||
diskUsed: formatBytes(systemMetrics.disk.used)
|
||||
},
|
||||
|
||||
// Mock data for features not yet implemented
|
||||
recentActivity: [
|
||||
{
|
||||
action: 'User login',
|
||||
user: 'john@example.com',
|
||||
timestamp: new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString(),
|
||||
type: 'info'
|
||||
},
|
||||
{
|
||||
action: 'Password reset',
|
||||
user: 'jane@example.com',
|
||||
timestamp: new Date(Date.now() - 4 * 60 * 60 * 1000).toISOString(),
|
||||
type: 'warning'
|
||||
},
|
||||
{
|
||||
action: 'User created',
|
||||
user: 'admin@monacousa.org',
|
||||
timestamp: new Date(Date.now() - 6 * 60 * 60 * 1000).toISOString(),
|
||||
type: 'success'
|
||||
}
|
||||
],
|
||||
|
||||
securityAlerts: [
|
||||
{
|
||||
id: 1,
|
||||
title: 'Failed Login Attempts',
|
||||
description: '3 failed login attempts detected',
|
||||
severity: 'medium',
|
||||
timestamp: new Date(Date.now() - 1 * 60 * 60 * 1000).toISOString()
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'System Update Available',
|
||||
description: 'Security update available for Keycloak',
|
||||
severity: 'low',
|
||||
timestamp: new Date(Date.now() - 12 * 60 * 60 * 1000).toISOString()
|
||||
}
|
||||
]
|
||||
// Basic portal health without system metrics
|
||||
portalStatus: 'online',
|
||||
lastUpdate: new Date().toISOString()
|
||||
};
|
||||
|
||||
console.log('✅ Admin stats retrieved successfully with real system metrics');
|
||||
console.log('✅ Simple admin stats retrieved successfully');
|
||||
return stats;
|
||||
|
||||
} catch (error: any) {
|
||||
@@ -100,7 +39,7 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to retrieve system statistics'
|
||||
statusMessage: 'Failed to retrieve admin statistics'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user