【问题标题】:Identify firebase auth and database query timeout in react native在本机反应中识别firebase身份验证和数据库查询超时
【发布时间】:2019-03-19 03:16:50
【问题描述】:

问题背景

我所说的这个应用是使用 react native 开发的。

在我正在开发的应用程序中,有两种使用 firebase 的方法。一种是查询数据库以获取一些数据,另一种是用于 Firebase 身份验证。

问题

当我调用 firebase.database() 函数和 firebase.auth() 函数时,可能会出现路由器阻塞 firebase 请求等网络连接问题。在这种情况下,firebase 函数需要回复,但不会收到。这将是一个关于应用程序的巨大用户体验问题。

那么有没有一种方法可以识别超时并为用户提供一些通知以更改网络或执行某些操作?

注意

使用 netinfo 我可以查看用户是否已连接到互联网。但如果firebase url被路由器阻止,则不会。所以我期待一个解决方案。

【问题讨论】:

  • 你为什么不在 firebase.auth().onAuthStateChanged(function(user) {}之后调用你的 firebase.database() 函数> 功能?
  • 但是在任何请求过程中都可能出现网络错误对吧?无论是用于查询还是对用户进行身份验证。
  • 你能解释一下什么是“路由器”吗? react-router-flux?请提供有关您的工作流程的代码示例以澄清问题。
  • 路由器,我的意思是物理路由器。一些组织通过其路由器阻止某种 URL

标签: firebase react-native firebase-realtime-database firebase-authentication timeout


【解决方案1】:

如果网站被路由器/防火墙阻止,请求响应将是 403 : Forbidden。

您可以使用fetch() 对其进行测试并通知用户响应为 403。

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

【讨论】:

    猜你喜欢
    • 2020-12-22
    • 2017-12-25
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2022-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多