capacitor-firebase icon indicating copy to clipboard operation
capacitor-firebase copied to clipboard

Error: `Unable to process request due to missing initial state.`

Open braincomb opened this issue 4 years ago • 13 comments

Is your feature request related to a problem? Please describe:

There's currently an issue with the authentication flow where in some cases upon calling the Callback URL (default myapp.firebaseapp.com/__/auth/handler provided by Firebase) the external browser will show this error: "Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared."

There's a GitHub issue open for this: https://github.com/firebase/firebase-js-sdk/issues/4256

From my own testing and troubleshooting I've concluded that in my experience this only happens with mobile Firefox. However, if we go to Firefox advanced settings and toggle "Open Links in App" to on, then the authentication proceeds as normal by redirecting back to the Capacitor app. Other browsers tested such as Chrome, Brave and Samsung Internet all work normally.

This leads me to believe that if force the authentication to open in a WebView, then we normalize the experience for all users, regardless of what their default web browser is set to.

Describe the solution you'd like:

If possible, force (or as configurable option) the authentication flow to go through @capacitor/browser instead of an external browser.

Additional context:

I'm unsure if the solution belongs to this plugin, but I thought this was a good place to start. Any advice appreciated!

braincomb avatar Nov 05 '21 20:11 braincomb

Hi @braincomb, interesting thought. I need to do some research. On which platform does the problem occur? Native Android, Native iOS or Web?

robingenz avatar Nov 05 '21 21:11 robingenz

Hi @robingenz ,

This was tested on a physical Android device running your plugin with native auth. Firefox was the only browser that showed the error and did not redirect back to the app.

For iOS I was only able to test with XCode emulator, no issues there.

EDIT: I'd like to add that this only happens with Twitter provider. My guess is that any provider that uses a Callback URL will open an external browser for the redirect. Google provider works fine which opens a popup on the phone.

braincomb avatar Nov 05 '21 21:11 braincomb

Thank you for the information. I was able to reproduce the issue with Twitter and GitHub Sign In on Android. I have created a Firebase App Check plugin for Capacitor (see here), since that was a suggested solution in the thread you linked. It is still a development version. Unfortunately it did not help in my case. It works in my Firefox only if I manually enable the Open links in apps option in the settings (see mozilla support).

Regarding your suggestion: Unfortunately I could not find a way to tell the Firebase SDK which browser to open. I will leave this issue open and mark it as help wanted. Maybe we will find a solution in the future. Unfortunately, at the moment I have no other ideas how this problem could be solved by the plugin.

robingenz avatar Nov 06 '21 12:11 robingenz

@robingenz Thank you for looking into this.

Interestingly enough, step 3 under Handle the sign-in flow with the Firebase SDK from the Authenticate Using Twitter on Android actually states:

Note that unlike other FirebaseAuth operations, this will take control of your UI by popping up a Custom Chrome Tab.

Which from our testing showed it doesn't.

I have also looked at how Facebook authentication behaves since it also uses a callback URL, and noticed that it opens a Custom Tab. Granted some extra configuration needed to be done in XML files.

Would something similar be possible to achieve here for Twitter auth to use a custom tab?

braincomb avatar Nov 06 '21 17:11 braincomb

@braincomb I am very busy this week. I will have a look at it this weekend/next week.

robingenz avatar Nov 09 '21 13:11 robingenz

I have also looked at how Facebook authentication behaves since it also uses a callback URL, and noticed that it opens a Custom Tab.

What do you mean exactly? Does a Google Chrome Custom Tab appear even though you have Firefox as your default browser? Or how did you notice that?

Granted some extra configuration needed to be done in XML files.

Which changes were made exactly? Do you have references?

robingenz avatar Nov 12 '21 17:11 robingenz

What do you mean exactly? Does a Google Chrome Custom Tab appear even though you have Firefox as your default browser? Or how did you notice that?

Yes, exactly, Chrome Custom Tab always opens regardless of what the default browser is.

Which changes were made exactly? Do you have references?

This is from your Facebook Setup documentation: there's an activity for CustomTabActivity which I'm assuming is what makes it use the Custom Tab. But I'm now thinking that this configuration is controlled by either Facebook SDK or Firebase SDK.

Either way, it looks like Firebase documentation claims that a Custom Tab should open for Twitter auth, but that is not the case. I'll see if I can open a bug issue with them.

braincomb avatar Nov 14 '21 22:11 braincomb

@braincomb You don't have Google Container plugin active? The login won't work with containers.

hnnweb avatar Feb 06 '22 22:02 hnnweb

Hi, was a solution ever found to this? We are getting an issue where Facebook Compliance is unable to successfully test our Login integration because they are getting this error -- we can't seem to reproduce it on any other devices. But it's this exact same error.

The login pop-up window just shows them a white screen.

Is there any way to get CapacitorFirebase to use redirect instead of PopUp?

lincolnthree avatar Oct 21 '22 16:10 lincolnthree

Hi, was a solution ever found to this? We are getting an issue where Facebook Compliance is unable to successfully test our Login integration because they are getting this error -- we can't seem to reproduce it on any other devices. But it's this exact same error.

The login pop-up window just shows them a white screen.

Is there any way to get CapacitorFirebase to use redirect instead of PopUp?

Unfortunately there is no solution so far.

Is there any way to get CapacitorFirebase to use redirect instead of PopUp?

  • Android/iOS: not possible
  • Web: not implemented

robingenz avatar Oct 21 '22 17:10 robingenz

  • Android/iOS: not possible

Right.

  • Web: not implemented

Yes, this is the platform I was wondering about. I suppose we could call the Firebase API manually. Any plans for supporting this? Thanks.

lincolnthree avatar Oct 21 '22 18:10 lincolnthree

I suppose we could call the Firebase API manually.

Yes

Any plans for supporting this? Thanks.

Not yet, but feel free to create a feature request and I'll put it on the raodmap.

robingenz avatar Oct 21 '22 19:10 robingenz

Done, thanks: https://github.com/capawesome-team/capacitor-firebase/issues/224

lincolnthree avatar Oct 24 '22 16:10 lincolnthree