3

I have a Cordova/ionic/angular app that uses Firebase auth and works perfectly in a browser and in an emulator. On a real device, however, calls to firebase.auth() return error-code "auth/network-request-failed", indicating that a network error (such as timeout, interrupted connection or unreachable host) has occurred. This occurs when I run device-debug from, in my case, Visual Studio but also when I install the app on a device (Android phone) and simply run it.

The firebase code is:

<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase.js"></script>

I have already replaced the <form> stuff with simple <div>s in the template because I read here that it could cause a re-submit which triggers the network error. I have tried the button both with a <button> directive and with the <a> directive. No difference. Unless angular or ionic do some magic that messes up the directives, this ought to be clean but you never know.

The following security meta-tag is also included as it was posted here as a possible solution to the problem:

<meta "content_security_policy":"script-src 'self' https://apis.google.com https://www.googleapis.com https://securetoken.googleapis.com; object-src 'self'" , "permissions": [ "https://*/*", "activeTab" ] >

The js code shouldn't be the issue as the app is working fine in a browser but I am including it anyway:

firebase.auth().signInWithEmailAndPassword(email, password)
   .then(() => { ... }
   .catch(error => {
      console.log(error.code, error.message);
   });

Lastly, I have an onAuthStateChanged observer attached. The observer does get initialized on the device but it never fires - of course - because the auth() call returns an error.

What am I doing wrong? Any help is highly appreciated.

Community
  • 1
  • 1
  • To be any help troubleshooting, we'd need a working repro to verify and tinker. See [how to ask](http://stackoverflow.com/help/how-to-ask) and [creating an mcve](http://stackoverflow.com/help/mcve). For your own efforts, I'd start by [turning on debug logging](https://gist.github.com/katowulf/ed3236d26e60ab3b4b855f89f20df517), which may shed some light in where the failure occurs. – Kato Dec 19 '16 at 22:10
  • 1
    I found a workaround rather than a solution: created a brand new cordova project and copied the www path from the malfunctioning project. Firebase works like a charm after that, even when debugging a device. – Punchcard Coder Dec 21 '16 at 09:00

0 Answers0