Files
cs249r_book/tinytorch/site/extra/community/auth_callback.html
2026-02-10 10:25:11 -05:00

89 lines
3.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Authenticating...</title>
<style>
body {
font-family: 'Courier New', Courier, monospace;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f0f4f8;
}
.spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
width: 36px;
height: 36px;
border-radius: 50%;
border-left-color: #ff6600;
animation: spin 1s linear infinite;
margin-bottom: 20px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="spinner"></div>
<p>Completing authentication...</p>
<script type="module">
import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm';
import { SUPABASE_PROJECT_URL, SUPABASE_ANON_KEY } from './modules/config.js';
const supabase = createClient(SUPABASE_PROJECT_URL, SUPABASE_ANON_KEY);
// Supabase will automatically pick up the session from the URL hash
supabase.auth.onAuthStateChange((event, session) => {
if (event === 'SIGNED_IN' && session) {
console.log("Session detected in callback, sending to opener...");
if (window.opener) {
window.opener.postMessage({
type: 'TINY_TORCH_AUTH_SUCCESS',
session: session
}, window.location.origin);
// Give a small delay to ensure message is sent before closing
setTimeout(() => window.close(), 500);
} else {
// Fallback if not in a popup
window.location.href = './index.html';
}
} else if (event === 'SIGNED_OUT') {
// If we got here and we're signed out, maybe something failed
console.error("Auth callback: Signed out event");
}
});
// Check if session exists immediately (sometimes event doesn't fire if already set)
supabase.auth.getSession().then(({ data: { session } }) => {
if (session) {
if (window.opener) {
window.opener.postMessage({
type: 'TINY_TORCH_AUTH_SUCCESS',
session: session
}, window.location.origin);
setTimeout(() => window.close(), 500);
} else {
window.location.href = './index.html';
}
}
});
// Safety timeout to close window if nothing happens
setTimeout(() => {
if (!window.opener) return;
// Only auto-close if we've been here too long without success
// window.close();
}, 30000);
</script>
</body>
</html>