Fixed google login
This commit is contained in:
@@ -64,34 +64,29 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
<script>
|
||||
(function() {
|
||||
try {
|
||||
// Store tokens in the parent window's localStorage
|
||||
if (window.opener && !window.opener.closed) {
|
||||
window.opener.localStorage.setItem('google_access_token', '${tokens.access_token}');
|
||||
window.opener.localStorage.setItem('google_refresh_token', '${tokens.refresh_token}');
|
||||
|
||||
// Send success message to parent
|
||||
window.opener.postMessage({
|
||||
type: 'GOOGLE_AUTH_SUCCESS',
|
||||
tokens: {
|
||||
accessToken: '${tokens.access_token}',
|
||||
refreshToken: '${tokens.refresh_token}'
|
||||
}
|
||||
}, '*');
|
||||
|
||||
// Close the popup after a short delay to ensure message is received
|
||||
setTimeout(() => {
|
||||
// Store tokens in localStorage (same origin)
|
||||
localStorage.setItem('google_access_token', '${tokens.access_token}');
|
||||
localStorage.setItem('google_refresh_token', '${tokens.refresh_token}');
|
||||
// Set timestamp that the main application will detect
|
||||
localStorage.setItem('google_auth_timestamp', Date.now().toString());
|
||||
|
||||
// Update UI to show success
|
||||
document.querySelector('.loading').textContent = 'Authentication complete! This window will close automatically.';
|
||||
|
||||
// Close window after a short delay
|
||||
setTimeout(() => {
|
||||
try {
|
||||
window.close();
|
||||
}, 500);
|
||||
} else {
|
||||
// If no opener, close immediately
|
||||
window.close();
|
||||
}
|
||||
} catch (e) {
|
||||
// If we can't close automatically, update message
|
||||
document.querySelector('.loading').textContent = 'Authentication complete! You can close this window now.';
|
||||
}
|
||||
}, 1500);
|
||||
} catch (error) {
|
||||
console.error('Error in auth callback:', error);
|
||||
// Try to close the window anyway
|
||||
setTimeout(() => {
|
||||
window.close();
|
||||
}, 1000);
|
||||
// Update UI to show error
|
||||
document.querySelector('.success').textContent = '✗ Authentication error';
|
||||
document.querySelector('.loading').textContent = 'Please close this window and try again.';
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user