120 lines
4.6 KiB
HTML
120 lines
4.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Google OAuth Callback</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
margin: 0;
|
|
background: #f5f5f5;
|
|
}
|
|
.container {
|
|
text-align: center;
|
|
padding: 40px;
|
|
background: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
}
|
|
.spinner {
|
|
border: 4px solid #f3f3f3;
|
|
border-top: 4px solid #3498db;
|
|
border-radius: 50%;
|
|
width: 40px;
|
|
height: 40px;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto 20px;
|
|
}
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="spinner"></div>
|
|
<p>Completing authentication...</p>
|
|
<p style="font-size: 12px; color: #999;">Please wait, you'll be redirected shortly.</p>
|
|
</div>
|
|
|
|
<script>
|
|
console.log('callback.html loaded')
|
|
console.log('URL:', window.location.href)
|
|
|
|
// Extract parameters from URL
|
|
const params = new URLSearchParams(window.location.search)
|
|
const accessToken = params.get('access_token')
|
|
const eventId = params.get('event_id')
|
|
const error = params.get('error')
|
|
|
|
console.log('accessToken:', accessToken ? 'present' : 'missing')
|
|
console.log('eventId:', eventId)
|
|
console.log('error:', error)
|
|
|
|
// Determine the base URL
|
|
const baseUrl = window.location.origin
|
|
|
|
if (accessToken && eventId && eventId !== 'default') {
|
|
console.log('Setting up Google import with event:', eventId)
|
|
|
|
// Fetch user's email from Google
|
|
console.log('Fetching user info from Google...')
|
|
fetch('https://www.googleapis.com/oauth2/v2/userinfo', {
|
|
headers: {
|
|
'Authorization': `Bearer ${accessToken}`
|
|
}
|
|
})
|
|
.then(response => {
|
|
console.log('Google userinfo response:', response.status)
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`)
|
|
}
|
|
return response.json()
|
|
})
|
|
.then(userInfo => {
|
|
console.log('Got user info from Google:', userInfo.email)
|
|
// Store in sessionStorage so the GuestList component can pick them up
|
|
sessionStorage.setItem('googleAccessToken', accessToken)
|
|
sessionStorage.setItem('googleEventId', eventId)
|
|
sessionStorage.setItem('googleUserEmail', userInfo.email) // Store the actual Gmail account
|
|
sessionStorage.setItem('googleImportPending', 'true')
|
|
|
|
console.log('sessionStorage set with email:', userInfo.email)
|
|
|
|
// Redirect to the app with the full path to guests page
|
|
const redirectUrl = `/events/${encodeURIComponent(eventId)}/guests`
|
|
console.log('Redirecting to:', redirectUrl)
|
|
window.location.href = redirectUrl
|
|
})
|
|
.catch(error => {
|
|
console.error('Error fetching user info:', error)
|
|
// Still proceed with redirect even if we can't get email
|
|
sessionStorage.setItem('googleAccessToken', accessToken)
|
|
sessionStorage.setItem('googleEventId', eventId)
|
|
sessionStorage.setItem('googleImportPending', 'true')
|
|
|
|
const redirectUrl = `/events/${encodeURIComponent(eventId)}/guests`
|
|
console.log('Redirecting to (without email):', redirectUrl)
|
|
window.location.href = redirectUrl
|
|
})
|
|
} else if (accessToken && eventId === 'default') {
|
|
console.log('No specific event, redirecting to home')
|
|
// No specific event, stay on home page with token
|
|
window.location.href = `/?access_token=${encodeURIComponent(accessToken)}`
|
|
} else if (error) {
|
|
console.log('OAuth error:', error)
|
|
// Redirect with error
|
|
window.location.href = `/?error=${encodeURIComponent(error)}`
|
|
} else {
|
|
console.log('No valid parameters')
|
|
// No valid parameters, go back to home
|
|
window.location.href = '/'
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|