Call external method from this.$ in polymer

132 Views Asked by At

I am new to polymer and I have a few problems. I have the following code polymer code for my polymerfire registration page.

        Polymer({
        is: 'my-register',
        properties: {
            message: {
                type: String,
                value: '',
            },
            email:{
                type: String,
                value: '',
            },
            password: {
                type: String,
                value: '',
            },
            user: {
                type: Object,
                notify: true,
            },
            customUser: {
                value: {},
                notify: true,   
            },
        },
        loginSuccess: function(){
            this.customUser['status'] = 1;
            if(this.customUser['status'] == 1 && this.message == ""){
                console.log("done");
                // this.$.ironLocation.set('path', '/profile');
            }
        },
        createUserWithEmailAndPassword: function() {
            this.error = null;
            this.$.auth.createUserWithEmailAndPassword(this.email, this.password) 
                .then(function(response) {
                    this.loginSuccess();
                    console.log("success");
                })
                .catch(function(error) {
                    console.log("Error");
                });
            this.password = null;
        },
        ready: function(){
            this.customUser['status'] = 0;
        },
        handleError: function(e) {
            this.message = 'Error: ' + e.detail.message;
        },
        signOut: function() {
            this.error = null;
            this.$.auth.signOut();
        },  
    });

The problem is that I can't call the loginSuccess function from the createUserWithEmailAndPassword success function. Is it possible to access external methods from the firebase-auth create function?

And is there a way to track custom attributes in the firebase user object instead of creating a second custom user object? I don't think this is very efficient because I have to access both properties in the whole application.

1

There are 1 best solutions below

1
On BEST ANSWER

You can try this..

createUserWithEmailAndPassword: function () {
  var self = this;
  // Or ES6
  // let self = this;       
  this.error = null;
   this.$.auth.createUserWithEmailAndPassword(this.email, this.password) 
     .then(function (response) {
       self.loginSuccess();
       console.log("success");
     }).catch(function (error) {
        console.log("Error");
     });

   this.password = null;
}

I use this trick and work for me.

Cheers..!