baumblatt / capacitor-firebase-auth

Capacitor Firebase Authentication Plugin
MIT License
261 stars 129 forks source link

Error: Scripts may close only the windows that were opened by them. #130

Open camilobenito opened 3 years ago

camilobenito commented 3 years ago

Hi,

When trying the latest version on android, the cfaSignIn function opens a new Chrome window (external to the app) and shows the Google screen to select an account. After selecting an account it redirects to a blank screen and nothing happens after that.

After debugging I have found out the this new Chrome window generates the following alert: handler.js:172 Scripts may close only the windows that were opened by them.

I'm guessing that this stops the window from closing and therefore the signin process doesn't complete by sending the result back to the App.

Do you have any recommendations on how to solve this?

Thank you

camilobenito commented 3 years ago

I tried this on another android device with a previous android version and this time the Chrome tab closes but then Android stays on the chrome window. It does not switch back to the App. If I manually switch back to the app it is still waiting for the callback.

baumblatt commented 3 years ago

Hi Camilo,

This sounds a little strange, on Google Sign-In the plugin call the Firebase SDK, and in this case, there is a native interface and not a browser window, can you please share more detail of your project?

Best regards.

cecilkootz commented 3 years ago

I am experiencing the same issue. To debug a bit I setup a fresh project only configured for Capacitor using Quasar and login works as expected. However when I have firebase initialized for cross-device support I get the same behavior described above where calling cfaSignIn opens a browser page.

I am continuing to test different options...is there any areas best to look for debug/troubleshooting?

export function socialLogin ({ dispatch }, providerId) {
  const isApp = Platform.is.capacitor
  if (isApp) {
    dispatch('nativeLogin', providerId)
  } else {
    dispatch('redirectLogin', providerId)
  }
}

export function nativeLogin ({ dispatch }, providerId) {
  cfaSignIn(providerId).subscribe(() => {
    dispatch('routeUserToHome')
  })
}

export const redirectLogin = async function ({}, providerId) {
  const $fb = this.$fb
  return await $fb.loginWithSocialProvider(providerId)
}
export const loginWithSocialProvider = (providerId) => {
  firebase.auth().useDeviceLanguage()
  let provider = null
  switch (providerId) {
    case 'google.com':
      provider = new firebase.auth.GoogleAuthProvider()
      provider.addScope('https://www.googleapis.com/auth/userinfo.profile')
      break
    default:
      console.log('No valid provider found.')
  }
  return firebase.auth().signInWithRedirect(provider)
}
cecilkootz commented 3 years ago

Quick update from further testing - if I start a new quasar project and setup capacitor-firebase-auth first, then bring in the remaining source from a backup - everything works. Guessing there is some initial build/config change that Quasar maybe doing.