Files
Job-Info/Mode2Test/AuthAndToken/frontend/index.html
T

70 lines
2.0 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mode2Test</title>
<script>
// Redirect to appropriate page based on auth status
async function checkAuthAndRedirect() {
try {
const response = await fetch('/api/auth/status');
const data = await response.json();
if (data.authenticated) {
// Redirect to home
window.location.href = '/home.html';
} else {
// Redirect to signin
window.location.href = '/signin.html';
}
} catch (err) {
// On error, go to signin
window.location.href = '/signin.html';
}
}
checkAuthAndRedirect();
</script>
</head>
<body>
<div style="text-align: center; padding: 50px;">
<p>Redirecting...</p>
</div>
</body>
</html>
} catch {
window.location.href = '/signin.html';
return;
}
}
// Logged in - show app
document.getElementById('userName').textContent = pb.authStore.model?.display_name || pb.authStore.model?.email || 'User';
document.getElementById('userEmail').textContent = pb.authStore.model?.email || '';
const response = await fetch('/api/auth/tokens');
if (response.ok) {
const tokens = await response.json();
const pbValid = tokens.pbToken ? '✓ Valid' : '✗ Missing';
const graphValid = tokens.graphToken ? '✓ Valid' : '✗ Not acquired';
document.getElementById('tokenStatus').innerHTML = `
<div><p><strong>PocketBase Token:</strong> ${pbValid}</p></div>
<div><p><strong>Graph Token:</strong> ${graphValid}</p></div>
`;
}
}
function handleLogout() {
if (confirm('Logout?')) {
pb.authStore.clear();
fetch('/api/auth/logout', { method: 'POST' });
window.location.href = '/signin.html';
}
}
checkAuth();
</script>
</body>
</html>