1

I am trying to show a dom-if template only to some users, but I don't know how to do it. Here is a pseudocode of what I am trying to do:

 <template is="dom-if" if="{{user.isAdmin}}" restamp="true">
        <hr />
        <h1>Add new conference:</h1>
        <paper-input
        id="title"
        label="Título"
        type="text"
        name="title">
    </paper-input>
    <paper-fab id="saveFab" icon="cloud-upload" on-tap="add"></paper-fab>
</template>
<script>
        Polymer({
            is: 'my-conferences',
            properties: {
                data: Array,
                user: Object,
            },

...

Where "user" is the object that I got from the <firebase-auth> element. Something like user.isAdmin is what I would like to achieve.

Any ideas? Thank you!

zolastro
  • 918
  • 12
  • 29
  • Could you post a complete example of your code? Currently, I don't see any `dom-module` for your `my-conferences` element. If you don't have it, then this is your problem. If you do have it, then the problem lies elsewhere and we need to see more of your code in order to analize it. – alesc Jan 30 '17 at 19:08
  • I have the default polymer element structure (including the dom-module). Here all the source code: https://github.com/zolastro/HackersWeekMalaga/blob/master/src/my-app/my-conferences.html – zolastro Jan 30 '17 at 20:27
  • How do you authenticate your admin ? which authentication type do you use with firebase ? maybe have a look here: http://stackoverflow.com/questions/17607101/firebase-authenticate-as-admin – Niklas Jan 31 '17 at 09:54
  • I was using "google" as account provider. The idea was to allow one of these google account to be the admin. However, I will try out using `firebaseRef.authWithCustomToken`. – zolastro Jan 31 '17 at 11:34
  • did you have any luck creating a admin account ? – Niklas Apr 02 '17 at 15:27

1 Answers1

1

here is a way you could do this.

  1. Create a users record on you firebase with the same id.

then:

    <firebase-auth id="auth" provider="google" user="{{auth}}" on-error="showError">
</firebase-auth>

<app-user
    uid="[[auth.uid]]"
    user="{{user}}"></app-user>

App user element is

<script>
    (function() {
        'use strict';
        Polymer({
            is: 'app-user',

            properties: {
                uid: {
                    type: String,
                    reflectToAttribute: true,
                    notify: true,
                    observer: '_uidChanged'
                },
                user: {
                    type: Object,
                    value: null,
                    notify: true
                }
            },

            _uidChanged: function (uid) {

                if (this.uid) {
                    firebase.database().ref('/users/' + uid).once('value', function(snapshot) {
                        if (snapshot.val()) {
                            this.user = snapshot.val();
                        }
                    }.bind(this));

                }
            }
        });
    })();
</script>

let me know if you need more help.

Jobizzness
  • 84
  • 1
  • 4