应用程序离线时如何绕过Firebase身份验证?

时间:2020-10-20 12:20:50

标签: firebase flutter google-cloud-firestore firebase-authentication

我有以下情况:Flutter应用程序由AWS上的Spring Boot应用程序支持。用户首次尝试登录时,他们将通过OAuth2由Spring Security进行身份验证,并获得JWT令牌,该令牌将保留在应用程序的内存中以供将来进行交互。

除了第一个令牌之外,还有一个第二个Firebase令牌,该令牌用Firebase私钥签名,用于与Firestore数据库的所有交互。

Firebase连接得到了很好的处理,包括在Internet连接断开期间,但是只要用户尝试(首次或重新)打开应用程序且Internet连接不可用,它就会在Firebase登录期间挂起。

有什么办法可以绕过这个? 我知道如果没有Internet连接就无法进行身份验证,但是我希望允许用户在脱机时访问其Firestore本地缓存。

1 个答案:

答案 0 :(得分:1)

您可以启用离线持久性,在Web中默认情况下是禁用的:

firebase.firestore().enablePersistence()
  .catch(function(err) {
      if (err.code == 'failed-precondition') {
          // Multiple tabs open, persistence can only be enabled
          // in one tab at a a time.
          // ...
      } else if (err.code == 'unimplemented') {
          // The current browser does not support all of the
          // features required to enable persistence
          // ...
      }
  });

您可以了解更多here

相关问题