- Added HTTP server with CORS support and various endpoints - Introduced http_tx/http_rx channels for HTTP server control - Cleaned up build.rs by removing commented code - Updated .gitignore to use *.rdb pattern instead of .rdb - Simplified capabilities.json to empty object - Improved UI initialization with better error handling - Reorganized module imports in main.rs - Added worker count configuration for HTTP server The changes introduce a new HTTP server capability while cleaning up and improving existing code structure. The HTTP server includes authentication, session management, and websocket support.
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
// Handle authentication state
|
|
let currentUser = null;
|
|
let currentSession = null;
|
|
|
|
// Initialize auth with mock data
|
|
function initializeAuth() {
|
|
if (window.location.pathname.includes('auth')) {
|
|
return; // Don't initialize on auth pages
|
|
}
|
|
|
|
// Check for existing session
|
|
const sessionId = localStorage.getItem('sessionId');
|
|
if (sessionId) {
|
|
currentSession = mockSessions.find(s => s.id === sessionId) || mockSessions[0];
|
|
} else {
|
|
currentSession = mockSessions[0];
|
|
localStorage.setItem('sessionId', currentSession.id);
|
|
}
|
|
|
|
// Set current user
|
|
currentUser = mockUsers[0];
|
|
updateUserUI();
|
|
}
|
|
|
|
// Update UI based on auth state
|
|
function updateUserUI() {
|
|
const userAvatar = document.getElementById('userAvatar');
|
|
if (userAvatar && currentUser) {
|
|
userAvatar.textContent = currentUser.avatar;
|
|
}
|
|
}
|
|
|
|
// Handle login
|
|
function handleLogin(email, password) {
|
|
// In a real app, this would call an API
|
|
currentUser = mockUsers.find(u => u.email === email) || mockUsers[0];
|
|
currentSession = mockSessions[0];
|
|
localStorage.setItem('sessionId', currentSession.id);
|
|
updateUserUI();
|
|
window.location.href = '/desktop/index.html';
|
|
}
|
|
|
|
// Handle logout
|
|
function handleLogout() {
|
|
localStorage.removeItem('sessionId');
|
|
window.location.href = '/desktop/auth/login.html';
|
|
}
|
|
|
|
// Check auth state for protected routes
|
|
function checkAuth() {
|
|
if (!currentUser && !window.location.pathname.includes('auth')) {
|
|
window.location.href = '/desktop/auth/login.html';
|
|
}
|
|
}
|
|
|
|
// Initialize on page load
|
|
if (document.readyState === 'complete') {
|
|
initializeAuth();
|
|
} else {
|
|
window.addEventListener('load', initializeAuth);
|
|
}
|