Add login modal to landing page
- Show login modal when user is not authenticated - Add handleLogin, showLoginModal, closeLoginModal functions - Add login modal HTML with username/password form - Add CSS styles for modal Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,10 +27,73 @@ async function checkAuth() {
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.authenticated) {
|
||||
window.location.href = '/claude/login.html';
|
||||
// Show login modal instead of redirecting
|
||||
showLoginModal();
|
||||
return;
|
||||
}
|
||||
|
||||
// Update nav with username
|
||||
if (data.username) {
|
||||
document.querySelector('.nav-logo').textContent = `Claude Code (${data.username})`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Auth check failed:', error);
|
||||
console.error('[checkAuth] Error:', error);
|
||||
showLoginModal();
|
||||
}
|
||||
}
|
||||
|
||||
// Show login modal
|
||||
function showLoginModal() {
|
||||
const modal = document.getElementById('login-modal');
|
||||
if (modal) {
|
||||
modal.style.display = 'flex';
|
||||
}
|
||||
}
|
||||
|
||||
// Close login modal
|
||||
function closeLoginModal() {
|
||||
const modal = document.getElementById('login-modal');
|
||||
if (modal) {
|
||||
modal.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle login form submission
|
||||
async function handleLogin(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const username = document.getElementById('login-username').value;
|
||||
const password = document.getElementById('login-password').value;
|
||||
const errorDiv = document.getElementById('login-error');
|
||||
|
||||
try {
|
||||
const res = await fetch('/claude/api/login', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
// Login successful
|
||||
closeLoginModal();
|
||||
loadProjects();
|
||||
|
||||
// Update nav with username
|
||||
if (data.username) {
|
||||
document.querySelector('.nav-logo').textContent = `Claude Code (${data.username})`;
|
||||
}
|
||||
} else {
|
||||
// Show error
|
||||
errorDiv.textContent = data.error || 'Login failed';
|
||||
errorDiv.style.display = 'block';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[handleLogin] Error:', error);
|
||||
errorDiv.textContent = 'Login failed. Please try again.';
|
||||
errorDiv.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user