1

I'm using the firebase/polymerfire package from bower bower install firebase/polymerfire

how can i create some data in the database after a method has been triggered?

The document tag looks like it will display and update data. I would like to, when a user signs up, create some data for the user to use.

app.signInAnonymously = function() {
        this.error = null;
        this.$.auth.signInAnonymously();
        // add default data for the user template
      };

How can i use the default set() or push methods like the normal SDK?

How can i call this on an event from JavaScript?

When trying to bind a path to my document like

<firebase-document
 path="/"
 data="{{firebaseData}}">
</firebase-document>


 {{firebaseData}}

the data won't display, but I have authentication working.

Snewedon
  • 2,410
  • 2
  • 13
  • 27

1 Answers1

5

You can actually use the firebase api directly there since firebase-auth is already including it, but if you want to keep the element-based functionality you could do this:

Add an empty firebase-document to your template

<firebase-document id="mydoc"></firebase-document>

Then call its save function in your element

app.signInAnonymously = function() {
    this.error = null;
    this.$.auth.signInAnonymously();
    // add default data for the user template

    //set path to null somewhere to avoid overwriting data, I recommend doing it here since save's path update is lazy
    this.$.mydoc.path = null;

    //set data to the value to set/push
    this.$.mydoc.data = {/*your data*/};

    //call save, if the second parameter is falsey it'll call push to the first parameter if it's truthy it'll set the data to firstparam/secondparam
    this.$.mydoc.save('path/to/users', userid);
  };

As for getting data with firebase-document, check that you actually have data in your database and your security rules, if you still can't see your data then it might be related to this issue, do bear in mind that polymerfire is still in a pre-release state

Alan Dávalos
  • 2,568
  • 11
  • 19
  • How can I use the firebase.auth and firebase.database directly? – Snewedon Jun 09 '16 at 02:24
  • I guess you mean how to use the js api directly, in which case you should go check out the [various](https://firebase.google.com/docs/web/setup) [tutorials](https://firebase.google.com/docs/auth/web/manage-users) [they have](https://firebase.google.com/docs/database/web/start), then again, if you're already using polymer you might as well wait until polymerfire is properly released as it's somewhat easier to use – Alan Dávalos Jun 09 '16 at 16:22
  • This feels a bit strange since my `firebase-document` already has a path specified. Seems like it should have an `.addChild()` method or something along those lines. – Evan Caldwell Oct 02 '16 at 04:56