samedi 25 avril 2015

Storing user authentication data with EmberFire

I've tried looking at Firebase documentation & examples but can't figure out exactly how to store user information acquired from OAuth & AuthwithPassword.

Here's my Firebase callback & createUser action:

var session = Ember.Object.extend({
    ref : new Firebase("http://ift.tt/1DWdd0s"),

    addFirebaseCallback: function() {
        var session = this;

        this.get("ref").onAuth(function(authData) {
            if (authData) {
                session.set("isAuthenticated", true);
            } else if (authData && newUser) {
                session.get("ref").child("users").child(authData.uid).set({
                    provider: authData.provider,
                    name: getName(authData)
                });
            } else {
                session.set("isAuthenticated", false);
            }
        });
    }.on("init"),

createUser: function() {
    var session = this;
    return new Ember.RSVP.Promise(function(resolve, reject) {
        session.get('ref').createUser(function (error, user) {

            if (user) {
                var newUser = session.store.createRecord('user', {
                    name: user.name,
                    email: user.email,
                    password: user.password,
                });

                newUser.save();

                resolve(newUser);

            } else {
                reject(error);
            }
        }); 
    });
},

Here's my Route:

createUser: function() {
            var controller = this;
            controller.get('session').createUser().then(function(user) {

                }, function() {

                });
        },

My gist is here: http://ift.tt/1b2Bqb7

I'd appreciate if you can point me in the right direction. There are no error messages and I have no idea where to look for hints.




Aucun commentaire:

Enregistrer un commentaire