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

firebase-document/collection "reconnect" upon auth #108

Open
mm-gmbd opened this issue Feb 2, 2016 · 4 comments
Open

firebase-document/collection "reconnect" upon auth #108

mm-gmbd opened this issue Feb 2, 2016 · 4 comments

Comments

@mm-gmbd
Copy link

mm-gmbd commented Feb 2, 2016

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 :)

@ebidel
Copy link
Contributor

ebidel commented Feb 2, 2016

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

@mm-gmbd
Copy link
Author

mm-gmbd commented Feb 2, 2016

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?

@ebidel
Copy link
Contributor

ebidel commented Feb 2, 2016

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.

@mm-gmbd
Copy link
Author

mm-gmbd commented Feb 2, 2016

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants