'Firebase Project Results in "Auth/network-request-failed" error on login

I'm running into a strange problem with my Cordova Project that uses Firebase. It works perfectly in browser, but when I run my app on an emulator or phone (Android), (at least) the first login attempt per load always results in an "Auth/network-request-failed" error. Here is my relevant Firebase code:

<!-- Import Firebase JS -->
<script src="https://www.gstatic.com/firebasejs/3.2.1/firebase.js"></script>

<!-- Import Firebase Authentication-->
<script src="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.js"></script>
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.css" />

And here is my security meta-tag (which I heard could result in a similar 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"]>

EDIT: I have not changed any code but now I experience this error occasionally in browser (Chrome) as well, if less often. I can't find a pattern, although the issue seems to go away in a session after the user registers. Any help would be greatly appreciated, thank you so much.



Solution 1:[1]

I arrived at this answer with the help of Firebase support. It turns out that my button which was calling the login function was of type "submit," which was causing my page to refresh every time it was pressed. This would interrupt the authentication process, resulting in the "network-request-failed" error. To fix this get rid of type="submit" in the button.

Solution 2:[2]

Finally, I fixed this problem!

  1. Don't use form tag! I changed form tag into div tag then it works!!!
  2. Don't use input type="submit", as someone's answer up there.

So far, I am not really sure why. But that's the two places I have changed, and then the firebase sign up network problem finally fixed.

Solution 3:[3]

I have spent a great deal of time confused about this and it was only when I disabled the CORS Chrome extension when it began to work on Chrome.

Chrome Canary and Firefox without any CORS extension were fine too. I do not believe the submit type is at all relevant.

Solution 4:[4]

Well by the [CORS ORIGIN POLICY]1 chrome will not allow you to access any other sites without(http, https). It will Resolved once you host your website, for temporary testing purpose you can use Mozilla Firefox which allows you to access. Have a nice day!!

Solution 5:[5]

If you are using the "HTTPS Everywhere" extension, then go to the "HTTPS Everywhere" settings and click on the "Disable HTTPS Everywhere for this site" button. It helped me.

Solution 6:[6]

My problem was I was caching everything in my serviceworker.js file. So I added these lines:

if (
    url.origin === "https://securetoken.googleapis.com" ||
    url.origin === "https://apis.google.com" ||
    url.origin === "https://www.googleapis.com"
) {
    return;
}

Solution 7:[7]

For me I just added some event.preventdefault() and it works very well.

document.getElementById("submit").addEventListener("click", function(event){
  event.preventDefault()
});

Solution 8:[8]

Disable CORS Chrome plugin worked for me

Solution 9:[9]

So this happened to me and it turned out Privacy Badger suddenly added my app's firebase domain to its block lists, randomly and without warning after months of Mr. Badger being okay with it...

Allowing the firebase domain to set cookies (moving the slider all the way to the right) fixed the issue.

Solution 10:[10]

For those who are experiencing this issue using ReactJS or NextJS, one possible issue is that you are passing a reference to the input field, instead of the value of the field, to Firebase.

When using the useState or useRef hooks, ensure that you pass the value of the input field, for example emailRef.current.value.

Solution 11:[11]

It's been second time that I have this issue and spend some unreasonable time trying to find solution. So I'm post this for my future self (and hopefully someone else):

Make sure you either don't use firebase emulator or your emulator is enabled.