Skip to content

Don't wait resolving firebase.auth() when enablePersistence() is used #3302

Open
@mu3

Description

@mu3

Describe the problem

Once signed-in, internally Firestore starts to wait for auth to give its first credential changed event before enabling persistence.
The behaviour remains the same even if firebase.auth() is completely removed.
This verification doesn't actually change anything even if the Firestore rules have changed to return 403 on requested resources: cache is returned as-is, every time.

Steps to reproduce / Relevant Code:

firebase.firestore().enablePersistence();
console.log('Fetching data...');
firebase.firestore().doc('foo/bar').onSnapshot(snap => {
  console.log('Data source:', snap.metadata.fromCache ? 'cache' : 'server')
  console.log(snap.data())
})
// firebase.auth().signInAnonymously(); // Single call is enough
Fetching data...
‼‼️‼‼️ Waiting for internal call to firebase.auth()...
Data source: cache
► {hotdogStatus: "Not a sandwich"}
Uncaught Error in onSnapshot: FirebaseError: Missing or insufficient permissions.

firebase.auth().signOut() makes Firestore act offline-first again.
The same as removing IndexedDB > firebaseLocalStorageDb > firebaseLocalStorage > 0

Fetching data...
Data source: cache
► {hotdogStatus: "Not a sandwich"}
Uncaught Error in onSnapshot: FirebaseError: Missing or insufficient permissions.

Expected behavior:

When enablePersistence() is used along auth(), return cache right away.
It doesn't seem like a security breach. Especially because cache is returned in any case, just with a delay.
I don't feel comfortable using Local Storage workarounds to duplicate data:

import useLocalStorage from '@rehooks/local-storage';
...
const [data, setData] = useLocalStorage('cachedData', {});
...
firebase.firestore().enablePersistence()
firebase.firestore().doc('foo/bar').onSnapshot(snap => setData(snap.data()) )
firebase.auth();

Describe your environment

  • Operating System version: macOS Catalina
  • Browser version: Google Chrome 83.0.4103.116
  • Firebase SDK version: 7.15.2
  • Firebase Product: auth, firestore

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions