Mode2Test AuthAndToken component complete: login/logout working, token persistence, background refresh active, tested and verified
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Sign In - 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-gradient-to-br from-blue-500 to-indigo-600 min-h-screen flex items-center justify-center">
|
||||
<div class="bg-white p-12 rounded-2xl shadow-2xl text-center max-w-md w-[90%]">
|
||||
<h1 class="text-gray-800 mb-2 text-3xl font-bold">Mode2Test</h1>
|
||||
<p class="text-gray-600 mb-8">Sign in with your Microsoft account</p>
|
||||
|
||||
<button id="loginBtn" onclick="handleLogin()" class="w-full bg-blue-600 text-white border-none py-3.5 px-8 text-base rounded-md cursor-pointer transition-colors duration-200 font-medium hover:bg-blue-700 disabled:bg-gray-400">
|
||||
Sign in with Microsoft
|
||||
</button>
|
||||
|
||||
<div id="error" class="text-red-600 mt-4 hidden"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const pb = new PocketBase('https://pocketbase.ccllc.pro');
|
||||
|
||||
async function handleLogin() {
|
||||
const btn = document.getElementById('loginBtn');
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Signing in...';
|
||||
document.getElementById('error').classList.add('hidden');
|
||||
|
||||
try {
|
||||
const authData = await pb.collection('users').authWithOAuth2({ provider: 'microsoft' });
|
||||
|
||||
// Log what we got for debugging
|
||||
console.log('[Auth] OAuth response:', authData);
|
||||
console.log('[Auth] Meta:', authData?.meta);
|
||||
|
||||
// Try to extract graph token from various possible locations
|
||||
const graphToken =
|
||||
authData?.meta?.accessToken ||
|
||||
authData?.meta?.access_token ||
|
||||
authData?.meta?.graphAccessToken ||
|
||||
authData?.meta?.graph_token ||
|
||||
authData?.meta?.graphToken ||
|
||||
authData?.meta?.rawUser?.access_token ||
|
||||
'';
|
||||
|
||||
console.log('[Auth] Graph token found:', !!graphToken);
|
||||
|
||||
// Send to backend to store
|
||||
await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ pbToken: authData.token, graphToken: graphToken || undefined })
|
||||
});
|
||||
|
||||
// Redirect to app immediately
|
||||
window.location.href = '/index.html';
|
||||
} catch (err) {
|
||||
document.getElementById('error').textContent = err.message || 'Login failed';
|
||||
document.getElementById('error').classList.remove('hidden');
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Sign in with Microsoft';
|
||||
}
|
||||
}
|
||||
|
||||
// Check if already logged in
|
||||
if (pb.authStore.isValid) {
|
||||
window.location.href = '/index.html';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user