m8chaa Claude commited on
Commit
2ea2006
·
1 Parent(s): c50e808

fix: Use popup window for OAuth in iframe to avoid security restrictions

Browse files

- Change from parent window redirect to popup window approach
- Try parent window.open first, fallback to current window
- Handle security errors gracefully with fallback to current window redirect

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

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

securecheck-pro/frontend/src/components/AuthButton.tsx CHANGED
@@ -41,10 +41,21 @@ export default function AuthButton() {
41
  const isInIframe = window.parent !== window || window.top !== window
42
 
43
  if (isInIframe) {
44
- // If in iframe, open OAuth in parent window
45
  const authUrl = `${process.env.NEXT_PUBLIC_SUPABASE_URL}/auth/v1/authorize?provider=google&redirect_to=${encodeURIComponent(window.location.origin + '/auth/callback')}`
46
- console.log('Opening OAuth in parent window:', authUrl)
47
- window.parent.location.href = authUrl
 
 
 
 
 
 
 
 
 
 
 
48
  return
49
  }
50
 
 
41
  const isInIframe = window.parent !== window || window.top !== window
42
 
43
  if (isInIframe) {
44
+ // If in iframe, open OAuth in a new window/tab
45
  const authUrl = `${process.env.NEXT_PUBLIC_SUPABASE_URL}/auth/v1/authorize?provider=google&redirect_to=${encodeURIComponent(window.location.origin + '/auth/callback')}`
46
+ console.log('Opening OAuth in new window:', authUrl)
47
+
48
+ // Try to use parent's window.open if possible, otherwise use current window
49
+ try {
50
+ if (window.parent && window.parent.open) {
51
+ window.parent.open(authUrl, '_blank')
52
+ } else {
53
+ window.open(authUrl, '_blank')
54
+ }
55
+ } catch (error) {
56
+ console.warn('Failed to open OAuth in new window, falling back to current window:', error)
57
+ window.location.href = authUrl
58
+ }
59
  return
60
  }
61