0
votes

Problem Background

This app I’m talking about being developed using react native.

In an app that I’m working on, there are two methods that use firebase. One to query database to get some data and other for firebase authentication.

Problem

When I call firebase.database() function and firebase.auth() function, there might be a network connection problem such as router block firebase request. In such cases firebase function expects the reply but it will not be received. That would be a huge user experience problem regarding the app.

So is there a way that I can identify a timeout and provide some notification for the user to change the network or do something?

Note

Using netinfo I can find whether the user has connect to the internet. But not if firebase url is blocking by the router. So I’m expecting a solution for that.

1
Why don't you call your firebase.database() function after the firebase.auth().onAuthStateChanged(function(user) {} function ? - Maxence Machu
But network error might occur during any request right? Whether it’s for quering or to auth a user. - user6310980
Could you explain what is "Router" ? react-router-flux? And please provide code examples about your workflow to clarify the question. - Maxence Machu
Router in the sense I meant the physical router. Some organizations block some kind of URLs via their routers - user6310980

1 Answers

0
votes

If the website is blocked by the router / firewall a request response will be a 403 : Forbidden.

You can test it using fetch() and notify the user is response is 403.

fetch('https://yourfirebasetestendpoint')
    .then((response) => {
      console.log(response.status)
      if(response.status === 403){
         // The firebase is blocked
      }
    })
    .catch((error) => {
      console.error(error);
    });