FirebaseExtended / polymerfire

Polymer Web Components for Firebase
https://www.webcomponents.org/element/firebase/polymerfire
MIT License
459 stars 142 forks source link

Query not re-firing post login #245

Open eob opened 7 years ago

eob commented 7 years ago

The <firebase-query> element is not rebinding to the remote DB after signInWithCustomToken is being called in some circumstances for us.

Expected outcome

  1. A user logs into our website
  2. We generate them a custom Firebase token
  3. We log them into firebase
  4. The query re-fires, thus loading information the user is allowed to see

Actual outcome

After logging into firebase, the query does not re-fire and the data attribute of the query element is not filled with data.

Through manual inspection via the console, we can see that the authentication did happen correctly and the firebase-query element is correctly connected to the database. The following code, for example, works just fine:

In console:

let ref = firebaseQueryElement.db.ref(firebaseQueryElement.path);
ref.on('value', function(s) {console.log(s.val())} )
// Prints the correct data

So we believe this issue has something to do with event handling -- the connection's fine; the query just wasn't re-triggered.

Another twist: we're running a single page app. This problem only occurs the first time a user logs in (simulated in a private browsing window). If the user re-visits the site, thus resuming a session from cookies, the problem does not manifest.

Note that both cases ought to appear identical from the firebase perspective. We have our own separate authentication system, and we're generating web tokens on the fly in both cases. The only difference is the duration of time on the site the user remains unauthenticated.

Live Demo

We've fixed the problem with the following code:

var self = this;
this.$.firebaseAuth.signInWithCustomToken(response.token).then(
  function(resp) {    
     let oldPath = self.$.firebaseOauth.path;
     self.$.firebaseOauth.set('path', null);
     self.$.firebaseOauth.set('path', oldPath);            
   }
)

This was on a production site, so we don't have something you can try yourselves at the moment.

Steps to reproduce

Browsers Affected

tjmonsi commented 7 years ago

I think the query is not related to work along side having a user signed in. Thus, it will not re-fire because it doesn't have anything connected from the auth.

But I do believe that data should flow once there is a user authenticated, but I guess I think this is on firebase because if it already returned an error, it will not do the on() value?