chat / public /oauth-callback.html
incognitolm's picture
Initial
5383ef0 verified
Raw
History Blame
2.19 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Signing in…</title>
<style>
body { background: #0d0e11; color: #e8eaf0; font-family: system-ui, sans-serif;
display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
.box { text-align: center; }
.spinner { width: 32px; height: 32px; border: 3px solid rgba(229,200,70,0.2);
border-top-color: #e5c846; border-radius: 50%; animation: spin 0.8s linear infinite;
margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
</style>
</head>
<body>
<div class="box">
<div class="spinner"></div>
<p>Completing sign-in…</p>
</div>
<script>
// Extract tokens from URL hash (Supabase implicit flow) or search params
function getTokens() {
const hash = new URLSearchParams(location.hash.replace('#', ''));
const search = new URLSearchParams(location.search);
return {
access_token: hash.get('access_token') || search.get('access_token'),
refresh_token: hash.get('refresh_token') || search.get('refresh_token'),
error: hash.get('error') || search.get('error'),
error_desc: hash.get('error_description') || search.get('error_description'),
};
}
const tokens = getTokens();
if (tokens.error) {
document.querySelector('p').textContent = 'Sign-in error: ' + (tokens.error_desc || tokens.error);
} else if (tokens.access_token) {
// Post to opener (main tab) and close
if (window.opener && !window.opener.closed) {
window.opener.postMessage({
type: 'oauth:callback',
access_token: tokens.access_token,
refresh_token: tokens.refresh_token,
}, location.origin);
window.close();
} else {
// No opener — redirect to main page with params
const p = new URLSearchParams({ oauth: '1', t: tokens.access_token, r: tokens.refresh_token || '' });
location.replace('/?' + p.toString());
}
} else {
document.querySelector('p').textContent = 'No token received. Close this window.';
}
</script>
</body>
</html>