m8chaa Claude commited on
Commit
818b2e7
·
1 Parent(s): 9e60dcd

fix: Remove fallback redirect that was causing iframe navigation

Browse files

- Remove window.location.href fallback when popup blocked
- Prevent iframe from navigating to OAuth when popup opens
- Only use popup OAuth without affecting iframe content
- Fixes issue where both popup and iframe navigate to OAuth

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

securecheck-pro/frontend/src/components/AuthButton.tsx CHANGED
@@ -96,38 +96,31 @@ export default function AuthButton() {
96
 
97
  const authUrl = `${process.env.NEXT_PUBLIC_SUPABASE_URL}/auth/v1/authorize?provider=google&redirect_to=${encodeURIComponent(window.location.origin + '/auth/callback')}`
98
 
99
- try {
100
- const popup = window.open(authUrl, 'oauth', 'width=500,height=600,scrollbars=yes,resizable=yes')
101
-
102
- if (popup) {
103
- console.log('Popup opened successfully')
104
- // Listen for auth success message from popup
105
- const handleMessage = (event: MessageEvent) => {
106
- if (event.origin === window.location.origin && event.data?.type === 'AUTH_SUCCESS') {
107
- console.log('Received auth success from popup')
108
- popup.close()
109
- window.removeEventListener('message', handleMessage)
110
- // Refresh user session
111
- getUser()
112
- }
113
  }
 
114
 
115
- window.addEventListener('message', handleMessage)
116
 
117
- // Check if popup is closed manually
118
- const checkClosed = setInterval(() => {
119
- if (popup.closed) {
120
- clearInterval(checkClosed)
121
- window.removeEventListener('message', handleMessage)
122
- }
123
- }, 1000)
124
- } else {
125
- console.log('Popup blocked, using current window redirect')
126
- window.location.href = authUrl
127
- }
128
- } catch (error) {
129
- console.log('Popup failed, using current window redirect:', error)
130
- window.location.href = authUrl
131
  }
132
  return
133
  }
 
96
 
97
  const authUrl = `${process.env.NEXT_PUBLIC_SUPABASE_URL}/auth/v1/authorize?provider=google&redirect_to=${encodeURIComponent(window.location.origin + '/auth/callback')}`
98
 
99
+ const popup = window.open(authUrl, 'oauth', 'width=500,height=600,scrollbars=yes,resizable=yes')
100
+
101
+ if (popup) {
102
+ console.log('Popup opened, setting up communication')
103
+
104
+ // Listen for auth success message from popup
105
+ const handleMessage = (event: MessageEvent) => {
106
+ if (event.origin === window.location.origin && event.data?.type === 'AUTH_SUCCESS') {
107
+ console.log('Received auth success from popup')
108
+ popup.close()
109
+ window.removeEventListener('message', handleMessage)
110
+ // Refresh user session
111
+ getUser()
 
112
  }
113
+ }
114
 
115
+ window.addEventListener('message', handleMessage)
116
 
117
+ // Check if popup is closed manually
118
+ const checkClosed = setInterval(() => {
119
+ if (popup.closed) {
120
+ clearInterval(checkClosed)
121
+ window.removeEventListener('message', handleMessage)
122
+ }
123
+ }, 1000)
 
 
 
 
 
 
 
124
  }
125
  return
126
  }