New login view

This commit is contained in:
2025-06-26 08:37:04 -06:00
parent 91c651da48
commit fa64722020
7 changed files with 626 additions and 12 deletions

View File

@@ -14,11 +14,13 @@ let markers = [];
let userLocationMarker = null;
let isAddingLocation = false;
let refreshInterval = null;
let currentEditingLocation = null; // Add this line
let currentEditingLocation = null;
let currentUser = null; // Add current user state
// Initialize application when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
initializeMap();
checkAuthentication(); // Add authentication check
loadLocations();
setupEventListeners();
checkConfiguration();
@@ -222,6 +224,68 @@ function setupGeoFieldSync() {
});
}
// Check authentication and display user info
async function checkAuthentication() {
try {
const response = await fetch('/api/auth/check');
const data = await response.json();
if (data.authenticated && data.user) {
currentUser = data.user;
displayUserInfo();
}
} catch (error) {
console.error('Failed to check authentication:', error);
}
}
// Display user info in header
function displayUserInfo() {
const headerActions = document.querySelector('.header-actions');
// Create user info element
const userInfo = document.createElement('div');
userInfo.className = 'user-info';
userInfo.innerHTML = `
<span class="user-email">${escapeHtml(currentUser.email)}</span>
<button id="logout-btn" class="btn btn-secondary btn-sm" title="Sign out">
🚪 Logout
</button>
`;
// Insert before the location count
const locationCount = document.getElementById('location-count');
headerActions.insertBefore(userInfo, locationCount);
// Add logout event listener
document.getElementById('logout-btn').addEventListener('click', handleLogout);
}
// Handle logout
async function handleLogout() {
if (!confirm('Are you sure you want to logout?')) {
return;
}
try {
const response = await fetch('/api/auth/logout', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
});
if (response.ok) {
window.location.href = '/login.html';
} else {
showStatus('Logout failed. Please try again.', 'error');
}
} catch (error) {
console.error('Logout error:', error);
showStatus('Logout failed. Please try again.', 'error');
}
}
// Check API configuration
async function checkConfiguration() {
try {