firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.82k stars 884 forks source link

auth/network-request-failed when debugging on react native #2652

Open shirlev-wix opened 4 years ago

shirlev-wix commented 4 years ago

[REQUIRED] Describe your environment

[REQUIRED] Describe the problem

Getting an error when running on debug mode on the simulator (both for ios and android)

code: "auth/network-request-failed"
message: "A network error (such as timeout, interrupted connection or unreachable host) has 
occurred."

I created a small react native app to reproduce the bug: https://github.com/shirlev-wix/firebase-bug

return Promise.resolve()
        .then(() => firebase.initializeApp(options, this.name))
        .then(app => app.auth().signInWithCustomToken(authKey)

Thanks!

brloman commented 2 years ago

I can second this behavior. I tell my users to switch networks and use their phones hotspot to go around this issue.

brloman commented 2 years ago

I'm sure firebase team either don't care or don't know how to solve this issue, but they are definitely aware of it. There has been countless tickets and SO questions regrding that issue.

qq280948982 commented 2 years ago

Had the same issue

lewiscasewell commented 2 years ago

I have the same issue too. Works fine in mobile browsers, however, when downloading PWA, get (auth/network-request-failed) error. Then after, removing another app from firebase, to just have one web app for the project.. it works fine again.

FortyXD commented 2 years ago

Look, this can happen because the function does not have enough time to execute. Make it asynchronous. I solved the problem this way. Example:

 await this.fireservise.UpdateData(name,group).then(()=>{
        location.reload()
      })

 async UpdateData( name:string, grpup:string){
    const auth:any = getAuth();
  await updateProfile(auth.currentUser, {
     displayName: name, photoURL:  grpup
   }).then(() => {
     localStorage.setItem('Name',name)
     localStorage.setItem('Group',grpup)
   }).catch((error) => {
    alert("Error")
   });
  }
rpelissier commented 2 years ago

In case it helps someone. I had the same issue and lost many hours investigating. It turned out that in my case, it was simply a DNS issue in the firebase layer. localhost in the URL of the emulator was not resolved. I replaced it with 127.0.0.1 and it is working fine.

It would have been really easier if the error message was not hiding the stack trace.

guptavishesh143 commented 2 years ago

I also faced the same issue, but while switching the data networks it started working! I switched from Wifi to Mobile Data.

olivermen commented 1 year ago

I have the same issue. But I didn't find the solution yet. How can I fix that?

Maracaipe611 commented 1 year ago

Same problem here... My dependencies: { "firebase": "^9.12.1", "next": "12.2.5", "react": "18.2.0", }

Error message: Firebase: Error (auth/network-request-failed). I already checked all my authorized domains in console.firebase, and the other's requests like login & signing is fine. Just the reset password give me this error

wendelfreitas commented 1 year ago

Still happening when I try to mock firebase rest API using nock on jest

  "dependencies": {
    "@react-query-firebase/auth": "^1.0.0-dev.2",    "firebase": "^9.12.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-query": "^3.39.2",
    "react-router-dom": "^6.4.2",
  },
SSOURABH58 commented 1 year ago

Hi, can you elaborate on the steps? I am unable to get the DNS firebase layer part where exactly do I have to replace the localhost with 127.0.0.1? ( in my code or in the firebase or cloud console ??)

image
olivermen commented 1 year ago

Hello. Could you tell me about you please?

On Mon, Oct 31, 2022 at 3:42 AM SSOURABH58 @.***> wrote:

Hi, can you elaborate on the steps? I am unable to get the DNS firebase layer part where exactly do I have to replace the localhost with 127.0.0.1? ( in my code or in the firebase or cloud console ??) [image: image] https://user-images.githubusercontent.com/52000724/198989581-79793ea1-d06c-4052-9de6-2e8d9b63390e.png

— Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-js-sdk/issues/2652#issuecomment-1296904497, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2OTQAGIHZVWES4LK3ZRRHDWF6PABANCNFSM4KYPBC2A . You are receiving this because you commented.Message ID: @.***>

MarioBatalha commented 1 year ago

Someone here already solved this issue?

Rutvik17 commented 1 year ago

I am having the same issue, after some research I came across this https://github.com/firebase/firebase-js-sdk/issues/6322#issuecomment-1146598147 seems like configuring firebase for web in react native has an edge case. The emulators connect to different ports and causes the issue. Though I am not sure how to change my port on expo for the emulator. I tried creating a firebase.json file in the root folder and specify the ports and then run firebase emulators:start but it does not start the emulator. Errors out saying

Error when trying to check port 9099 on 10.0.2.2: Error: listen EADDRNOTAVAIL: address not available 10.0.2.2:9099

any suggestions ?

Rutvik17 commented 1 year ago
  • S proxy 8.8.8.8 for Android emulator.

Is this only a development issue or also happens on production. I am also facing the same issue. How do you set DNS proxy ?

ssmdssmp commented 11 months ago

For me solution was just to reload emulator. It suddenly had a pour connection, what I checked with db, so for me it was just an emulator bug.

servefast-cto commented 3 months ago

Same error for me as well