Firebase auth/operation-not-supported-in-this-environment with Capacitor

I’m having a problem with Capacitor when logging in to Firebase via GoogleAuthProvider.

const provider = new firebase.auth.GoogleAuthProvider();
let response = await firebase.auth().signInWithPopup(provider);

Login works fine in the browser when running as PWA, however it fails with the following error when running on iOS.

{“code”:“auth/operation-not-supported-in-this-environment”, “message”:“This operation is not supported in the environment this application is running on. “location.protocol” must be http, https or chrome-extension and web storage must be enabled.”}

Looks like a similar issue here, and the thread suggests that We don't support this environment. We only support Cordova apps for Android and iOS hosted from a file:// environment.

Does anyone have a workaround to get Firebase login to work in Capacitor?

I haven’t used Google Auth with Firebase/Capacitor, but the approach I took with Facebook was to use the cordova-plugin-facebook4 plugin to authenticate natively with Facebook outside of Firebase to grab the auth token, and then provide that directly to Firebase to authenticate (rather than having Firebase handle the Facebook auth itself). I assume a similar approach should be achievable with Google Auth.

1 Like

Thanks for the suggestion @joshmorony, I’ll try this approach. :+1:

Looks like capacitor-firebase-auth can do native Firebase login, although initially I haven’t had luck getting it to work in my Capacitor app but will keep trying.

Good news @joshmorony, I got Firebase Auth working in both the PWA and iOS/Android using the [capacitor-firebase-auth] plugin.

Big shout out to @baumblatt for helping resolve a build issue, plus adding scopes to the plugin :+1: