feat: add last_seen tracking for users

Adds last_seen field to track when users last accessed the tool:
- Add lastSeen column to users table schema (nullable timestamp)
- Create migration to add last_seen column to existing databases
- Add updateLastSeen() function to auth.service.js
- Update auth derive middleware to update last_seen on each authenticated request (async, non-blocking)
- Add lastSeen to admin getUserStats() query for display in admin users table
- Add "Last Seen" column to admin users table in frontend

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-01-23 09:57:45 +01:00
parent 24e0e3bfdb
commit d1e4c39ad6
6 changed files with 119 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import {
getUserById,
updateLoTWCredentials,
updateDCLCredentials,
updateLastSeen,
} from './services/auth.service.js';
import {
getSystemStats,
@@ -207,6 +208,14 @@ const app = new Elysia()
return { user: null };
}
// Update last_seen timestamp asynchronously (don't await)
updateLastSeen(payload.userId).catch((err) => {
// Silently fail - last_seen update failure shouldn't block requests
if (LOG_LEVEL === 'debug') {
logger.warn('Failed to update last_seen', { error: err.message });
}
});
// Check if this is an impersonation token
const isImpersonation = !!payload.impersonatedBy;