How to bypass Firebase authentication when app is offline?

731

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

Share:
731
Jaumzera
Author by

Jaumzera

I'm involved with computer programming since 1996 when I began my studies by myself with Clipper 5 and C/C++. Later I aimed my focus to PHP and during college towards developing Java EE applications. I planned and executed projects nationwide for small and large companies in financial and telecom sectors. I specialized myself in software engineering and I combine my knowledge with interest about code quality, design patterns, agile processes and techniques, open source tools, automated testing and continuous integration.

Updated on December 25, 2022

Comments

  • Jaumzera
    Jaumzera over 1 year

    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.