-
Notifications
You must be signed in to change notification settings - Fork 139
Query not re-firing post login #245
Description
The <firebase-query> element is not rebinding to the remote DB after signInWithCustomToken is being called in some circumstances for us.
Expected outcome
- A user logs into our website
- We generate them a custom Firebase token
- We log them into firebase
- 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.
- When logging in the first time (where the error manifests), it's ~7 seconds until the login occurs and we call
signInWithCustomToken. - When logging in times 2...N (where the error does not manifest), it's <1s until
signInWithCustomTokenis called
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
- Chrome
- Firefox
- Safari 9
- Safari 8
- Safari 7
- Edge
- IE 11
- IE 10