How to bypass Firebase authentication when app is offline?

Viewed 901

I have the following scenario: a Flutter application backed by a Spring Boot application on AWS. The first time a user tries to log in, they are authenticated by Spring Security with OAuth2 and get a JWT token which is kept in the app's memory for future interactions.

In addition to this first token, there is a secondary Firebase token, signed with a Firebase private key, which is used for all interactions with the Firestore database.

The Firebase connection is well handled, including during loss of Internet connectivity, but whenever a user tries to (first- or re)open the app and Internet connection is unavailable, it hangs during the Firebase sign in.

Is there any way to bypass this? I know they can't authenticate without an Internet connection, but I would like to allow users to access their Firestore local cache while they are offline.

1 Answers

You can enable offline persistence, in web it is disabled by default:

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
          // ...
      }
  });

You can learn more here

Related