polymerfirebase-authenticationfirebase-polymer

firebase-collection won't refresh data on firebase-auth login, if location doesn't include user value


If location (firebaseURL) in code below includes the user value (like auth.uid), then firebase-collection data will refresh on-login from firebase-auth. I am using Polymer 1.6.0

<firebase-auth id="auth"
      location="[[firebaseURL]]"
      provider="{{provider}}" 
      params="{{params}}"
      user="{{user}}">
    </firebase-auth>

    <firebase-collection
      location="[[firebaseURL]]"
      data="{{messages}}">
    </firebase-collection>

This is because on-login from firebase-auth the user value changes and that changes the location value, refreshing the data coming from firebase-collection.

However, if the location path doesn't include the user value, the data will not show up on-login, and you will have to refresh the page for that to happen.

The only way I have found so far to work around this limitation is a bit hackish.

I have to modify the html code for firebase-collection as follow:

<firebase-collection
      location="[[_location(user)]]"
      data="{{messages}}">
    </firebase-collection>

Adding the _location() function like this, to force the firebase-collection data to refresh and show up on-login

  _location: function(u){
    // hacking - to trigger the update firebase-collection/document on-login / on-user-change
    return this.user ? this.firebaseURL : "";
  }

It works but it doesn't look right to me.

Is there a better way, a more polymeric way?

Thanks

AskPolymer


Solution

  • You could use a dom-if to stamp firebase-collection conditionally on user:

    <template is="dom-if" if="[[user]]" restamp>
      <firebase-collection
        location="[[firebaseURL]]"
        data="{{messages}}">
      </firebase-collection>
    <template>