firebase-element icon indicating copy to clipboard operation
firebase-element copied to clipboard

firebase-document/collection "reconnect" upon auth

Open mm-gmbd opened this issue 9 years ago • 4 comments
trafficstars

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-document and firebase-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 :)

mm-gmbd avatar Feb 02 '16 17:02 mm-gmbd

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

ebidel avatar Feb 02 '16 19:02 ebidel

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:

  1. Monitor the auth status
  2. Once the auth is re-established, set location to ""
  3. Then set the location to the original location that was passed to firebase-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?

mm-gmbd avatar Feb 02 '16 20:02 mm-gmbd

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.

ebidel avatar Feb 02 '16 20:02 ebidel

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!

mm-gmbd avatar Feb 02 '16 20:02 mm-gmbd