mardi 3 février 2015

AngularFire $createUser 's promise doesn't return an object containing user data


According to the documentation the $createUser function, "... returns a promise that is resolved with an object containing user data about the created user"


http://ift.tt/1HUYS9m


When I use the function (see code below), I can register the user sucessfully but when I read the variable that should contain the UID, it's not defined.


In Chrome's console I get: "TypeError: Cannot read property 'uid' of undefined"


Am I doing something wrong? Should I be retrieving the value differently?



myApp.factory('Authentication', function($firebase, $firebaseAuth, FIREBASE_URL, $location, $rootScope) {
// using $firebaseAuth instead of SimpleLogin

var ref = new Firebase(FIREBASE_URL);
var authObj = $firebaseAuth(ref);

var myObject = {
login : function(user) {
console.log('authentication.js: logging in')
return authObj.$authWithPassword({
email: user.email,
password: user.password
});
}, //login

logout : function(){
return authObj.$unauth();
}, // logout

register : function(user) {
console.log('authentication.js: registering user')
return authObj.$createUser({
email: user.email,
password: user.password
}).then( function(userData) {
console.log("User " + userData.uid + " created successfully!");
});
} // register

} //myObject

return myObject;
});




Aucun commentaire:

Enregistrer un commentaire