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

85 lines
2.9 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 src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/pocketbase@0.26.5/dist/pocketbase.umd.js"></script>
</head>
<body class="font-sans bg-gray-50 min-h-screen">
<header class="bg-white shadow">
<div class="max-w-7xl mx-auto px-4 py-4 flex justify-between items-center">
<div>
<h1 class="text-2xl font-bold text-gray-800">Mode2Test</h1>
<p class="text-sm text-gray-600">Authenticated Application</p>
</div>
<div class="flex items-center gap-4">
<div id="userDisplay" class="text-right">
<p id="userName" class="text-sm font-medium text-gray-800"></p>
<p id="userEmail" class="text-xs text-gray-600"></p>
</div>
<button onclick="handleLogout()" class="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700">
Logout
</button>
</div>
</div>
</header>
<main class="max-w-7xl mx-auto px-4 py-8">
<div class="bg-white p-8 rounded-lg shadow">
<h2 class="text-xl font-bold mb-4 text-gray-800">Welcome to Mode2Test</h2>
<p class="text-gray-600 mb-6">Authenticated and ready to work.</p>
<div class="bg-gray-50 p-4 rounded border border-gray-200">
<h3 class="font-medium mb-2 text-gray-800">Token Status</h3>
<div id="tokenStatus" class="text-sm text-gray-600 space-y-2">
<p>Loading...</p>
</div>
</div>
</div>
</main>
<script>
const pb = new PocketBase('https://pocketbase.ccllc.pro');
async function checkAuth() {
if (!pb.authStore.isValid) {
// Try to refresh
try {
await pb.collection('users').authRefresh();
} 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>