firebase-element
firebase-element copied to clipboard
firebase-document/collection "reconnect" upon auth
I'm creating a single-page application that gets and displays some data through both firebase-document and firebase-collection. I'm running into an issue with the following workflow (using the more-router for switching between views):
- Login dialog is shown
- User logs in (login dialog disappears)
- Dashboard is shown
- Data is collected from Firebase (using
firebase-documentandfirebase-collection) and displayed - User logs out (dashboard is hidden, login dialog reappears)
- Same user logs in (login dialog disappears)
- Firebase queries do not "reconnect"
The reason for this is because the firebase-query-behavior function _onQueryCancel calls .disconnect() (link) which simply sets the location of the query to an empty string.
With the current architecture, a future "reconnect" upon re-auth is impossible considering the firebase-documents and firebase-collections already exist in the DOM, and are not reloaded (the "location" within the firebase-query-behavior is an empty string).
Maybe this should be altered to support? I'm now forced to move the login screen and all other screens to separate pages. Or maybe this is by design -- I'd just be interested to know why :)
Seems like an oversight. Have you tried to reset the .location property? That should re-establish a firebase instance.
https://github.com/GoogleWebComponents/firebase-element/blob/master/firebase-document.html#L94
So, the "location" that is passed to the element is done so via Polymer data binding:
<firebase-collection
location="[[location]]"
data="{{data}}">
</firebase-collection>
If I had location two-way bound using curly braces, then the firebase-collection essentially "nulls" the location that I had passed, hence the square braces. So, now that the location is not "nulled" by .disconnect(), I'm not sure the best way to "reset" the location property.
I am fairly new to Polymer, so apologies that it is not immediately apparent, but would the following work:
- Monitor the auth status
- Once the auth is re-established, set
locationto "" - Then set the
locationto the original location that was passed tofirebase-collection
I presume this would effectively notify the firebase-collection? Or, maybe let the location be two-way bound and then step 2 could be skipped?
I haven't taken a look a the code, but yea, it'll require a coordinated effort among the related components. The FirebaseQueryBehavior should remain unaware of auth.
Agreed that it should remain unaware.
However, saving the string, providing a status property (that describes whether or not the query is connected or disconnected), and then a .reconnect() method may be a nice feature. as opposed to just setting the location to an empty string.
I'm okay with closing, but I'll let you decide. Thanks!