Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase signInWithPopup gives auth/popup-blocked when used via built-in browser in mobile device

Tags:

Problem: When used via 3rd-party app built-in browser (e.g. LINE, Twitter or Facebook messenger), the signInWithPopup returns auth/popup-blocked. The explanation by Firebase docs is:

  • auth/popup-blocked: Thrown if the popup was blocked by the browser, typically when this operation is triggered outside of a click handler.

Typical sequence triggering this error is: Link of my web app is sent to LINE, Twitter or Facebook messenger. When user uses mobile device and opens that link in those apps, their built-in browser is opened. Calling signInWithPopup then returns the error. The behavior is slightly different in iOS and Android but at least iOS/LINE combination results the error.

I am using Angular and building a web app. The error message is Unable to establish a connection with the popup. It may have been blocked by the browser. which comes from the firebase.js - not my own text.

When used in a normal browser, the signup works just fine.

Any ideas why the built-in browsers and signInWithPopup do not work together?

like image 299
Hannu Hytönen Avatar asked Oct 06 '16 14:10

Hannu Hytönen


People also ask

What triggers onAuthStateChanged?

onAuthStateChanged. Adds an observer for changes to the user's sign-in state. Prior to 4.0. 0, this triggered the observer when users were signed in, signed out, or when the user's ID token changed in situations such as token expiry or password change.

What does Firebase auth () do?

Firebase Authentication provides backend services, easy-to-use SDKs, and ready-made UI libraries to authenticate users to your app. It supports authentication using passwords, phone numbers, popular federated identity providers like Google, Facebook and Twitter, and more.


2 Answers

Firebase authentication should start with some user interaction, such as click on button. This solved the problem for me.

like image 119
Zdeněk Mlčoch Avatar answered Sep 21 '22 13:09

Zdeněk Mlčoch


Many in-app embedded browsers block popups. I ran into the issue on instagram. Try using signInWithRedirect instead of signInWithPopup when kicking off the Oauth call.

Firebase documentation on usage of both methods can be found here - https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithPopup

like image 20
Tope Avatar answered Sep 22 '22 13:09

Tope