Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in sample: presence-firestore #813

Closed
dtran320 opened this issue Jan 3, 2021 · 0 comments · Fixed by #814
Closed

Bug in sample: presence-firestore #813

dtran320 opened this issue Jan 3, 2021 · 0 comments · Fixed by #814

Comments

@dtran320
Copy link
Contributor

dtran320 commented Jan 3, 2021

Which sample has a bug?

presence-firestore

How to reproduce the issue

  1. Install and deploy both the Firebase function and public directory to Firebase Hosting: cd functions && npm install && cd ../ && firebase deploy
  2. Visit the public endpoint for the deployed sample app to Firebase Hosting, e.g. example-123.web.app
  3. History of user presence (since this page was opened) shows on index.html, but index.js errors out due to missing firebase-database include.

Debug output

[Warning] TypeError: firebase.database is not a function. (In 'firebase.database()', 'firebase.database' is undefined) (index.js, line 155)
rtdb_and_local_fs_presence — index.js:70
(anonymous function) — index.js:152
(anonymous function) — promise.js:826
Re — promise.js:1166
Ce — promise.js:1140
(anonymous function) — promise.js:1111
fe — run.js:124
promiseReactionJob

[Warning] Please enable Anonymous Authentication in your Firebase project! (index.js, line 156)

Expected behavior

The following code in index.js results in User <Anonymous user id> is online being appended to the #history div in index.html, a status collection gets created in firestorm with a document for <Anonymous user id> and status/<Anonymous user id> gets added to Realtime Database.

firebase.firestore().collection('status')
        .where('state', '==', 'online')
        .onSnapshot(function(snapshot) {
            snapshot.docChanges().forEach(function(change) {
                if (change.type === 'added') {
                    var msg = 'User ' + change.doc.id + ' is online.';
                    console.log(msg);
                    // [START_EXCLUDE]
                    history.innerHTML += msg + '<br />';
                    // [END_EXCLUDE]
                }
                if (change.type === 'removed') {
                    var msg = 'User ' + change.doc.id + ' is offline.';
                    console.log(msg);
                    // [START_EXCLUDE]
                    history.innerHTML += msg + '<br />'
                    // [END_EXCLUDE]
                }
            });
        });

Actual behavior

The page errors out with the above javascript error due to the missing firebase.database function. Nothing gets written to Firestore or Realtime Database from the client as a result of running this sample.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant