Save local changes (GSC/Bing integrations) before merging PR #354
This commit is contained in:
@@ -53,26 +53,18 @@ export const useWordPressOAuth = (): UseWordPressOAuthReturn => {
|
||||
const THROTTLE_MS = 10000; // 10 seconds - status doesn't change frequently
|
||||
|
||||
if (now - lastStatusCheck < THROTTLE_MS) {
|
||||
console.log('WordPress OAuth: Status check throttled (10s)');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setIsLoading(true);
|
||||
setLastStatusCheck(now);
|
||||
console.log('WordPress OAuth: Checking status...');
|
||||
const status: WordPressOAuthStatus = await wordpressOAuthAPI.getStatus();
|
||||
|
||||
console.log('WordPress OAuth: Status response:', status);
|
||||
setConnected(status.connected);
|
||||
setSites(status.sites || []);
|
||||
setTotalSites(status.total_sites);
|
||||
|
||||
console.log('WordPress OAuth status checked:', {
|
||||
connected: status.connected,
|
||||
sitesCount: status.sites?.length || 0,
|
||||
totalSites: status.total_sites
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error checking WordPress OAuth status:', error);
|
||||
setConnected(false);
|
||||
@@ -108,23 +100,21 @@ export const useWordPressOAuth = (): UseWordPressOAuthReturn => {
|
||||
|
||||
// Listen for popup completion and messages
|
||||
const messageHandler = (event: MessageEvent) => {
|
||||
console.log('WordPress OAuth: Message received from any source:', {
|
||||
origin: event.origin,
|
||||
data: event.data,
|
||||
source: event.source === popup ? 'our-popup' : 'other'
|
||||
});
|
||||
|
||||
// Accept messages only from the popup we opened and from trusted origins
|
||||
const trustedOrigins = [window.location.origin, 'https://littery-sonny-unscrutinisingly.ngrok-free.dev'];
|
||||
const ngrokOrigin = process.env.REACT_APP_NGROK_ORIGIN || 'https://littery-sonny-unscrutinisingly.ngrok-free.dev';
|
||||
const productionOrigin = 'https://alwrity-ai.vercel.app';
|
||||
const trustedOrigins = [window.location.origin, ngrokOrigin, productionOrigin];
|
||||
|
||||
if (event.source !== popup) return;
|
||||
if (!trustedOrigins.includes(event.origin)) return;
|
||||
if (!trustedOrigins.includes(event.origin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('WordPress OAuth: Valid message from popup:', event.data);
|
||||
|
||||
if (event.data.type === 'WPCOM_OAUTH_SUCCESS') {
|
||||
popup.close();
|
||||
clearInterval(checkClosed);
|
||||
console.log('WordPress OAuth: Success message received, refreshing status...');
|
||||
// Refresh status after OAuth completion
|
||||
setTimeout(() => {
|
||||
checkStatus();
|
||||
@@ -132,7 +122,6 @@ export const useWordPressOAuth = (): UseWordPressOAuthReturn => {
|
||||
} else if (event.data.type === 'WPCOM_OAUTH_ERROR') {
|
||||
popup.close();
|
||||
clearInterval(checkClosed);
|
||||
console.error('WordPress OAuth error:', event.data.error);
|
||||
// Refresh status to show disconnected state
|
||||
setTimeout(() => {
|
||||
checkStatus();
|
||||
@@ -142,14 +131,10 @@ export const useWordPressOAuth = (): UseWordPressOAuthReturn => {
|
||||
|
||||
window.addEventListener('message', messageHandler);
|
||||
|
||||
// Test if popup is working
|
||||
console.log('WordPress OAuth: Popup opened, waiting for messages...');
|
||||
|
||||
const checkClosed = setInterval(() => {
|
||||
if (popup.closed) {
|
||||
clearInterval(checkClosed);
|
||||
window.removeEventListener('message', messageHandler);
|
||||
console.log('WordPress OAuth: Popup closed, refreshing status...');
|
||||
// Refresh status after OAuth completion
|
||||
setTimeout(() => {
|
||||
checkStatus();
|
||||
@@ -157,7 +142,6 @@ export const useWordPressOAuth = (): UseWordPressOAuthReturn => {
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
console.log('WordPress OAuth flow started');
|
||||
} else {
|
||||
throw new Error('Failed to get WordPress OAuth URL');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user