File size: 1,109 Bytes
bd62c3f
7769c20
 
 
 
bd62c3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

// Main application script
document.addEventListener('DOMContentLoaded', () => {
    console.log('ChatVite initialized');
    
    // Initialize all feather icons
    const replaceFeatherIcons = () => {
        if (window.feather) {
            feather.replace();
        } else {
            setTimeout(replaceFeatherIcons, 100);
        }
    };
    replaceFeatherIcons();

    // Handle authentication state
    const checkAuthState = () => {
        const currentUser = sessionStorage.getItem('currentUser');
        if (currentUser && window.location.pathname.endsWith('index.html')) {
            window.location.href = 'chat.html';
        } else if (!currentUser && !window.location.pathname.endsWith('index.html')) {
            window.location.href = 'index.html';
        }
    };
    checkAuthState();

    // Handle logout
    document.addEventListener('click', (e) => {
        if (e.target.closest('[data-logout]')) {
            sessionStorage.removeItem('currentUser');
            sessionStorage.removeItem('isAdmin');
            window.location.href = 'index.html';
        }
    });
});