Implemented sync functionality with sheets and email sending
This commit is contained in:
@@ -24,6 +24,19 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
throw redirect(302, '/private/events?error=incomplete_tokens');
|
||||
}
|
||||
|
||||
// Get user info to retrieve email
|
||||
let userEmail = '';
|
||||
try {
|
||||
oauth.setCredentials(tokens);
|
||||
const { google } = await import('googleapis');
|
||||
const oauth2 = google.oauth2({ version: 'v2', auth: oauth });
|
||||
const userInfo = await oauth2.userinfo.get();
|
||||
userEmail = userInfo.data.email ?? '';
|
||||
} catch (emailError) {
|
||||
console.error('Error fetching user email:', emailError);
|
||||
// Continue without email - it's not critical for the auth flow
|
||||
}
|
||||
|
||||
// Create a success page with tokens that closes the popup and communicates with parent
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
@@ -67,6 +80,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
// Store tokens in localStorage (same origin)
|
||||
localStorage.setItem('google_access_token', '${tokens.access_token}');
|
||||
localStorage.setItem('google_refresh_token', '${tokens.refresh_token}');
|
||||
${userEmail ? `localStorage.setItem('google_user_email', '${userEmail}');` : ''}
|
||||
// Set timestamp that the main application will detect
|
||||
localStorage.setItem('google_auth_timestamp', Date.now().toString());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user