Reputation: 1937
According to the documentation the $createUser function, "... returns a promise that is resolved with an object containing user data about the created user"
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;
});
Upvotes: 0
Views: 453
Reputation: 1937
The problem was that I was using an old version of Firebase. I was using version 2.0.4 and according to this post https://github.com/firebase/angularfire/issues/507 , to get the user object from the promise you need Firebase 2.0.5 or later and AngularFire 0.9.1 or later.
Using these CDN's now everything is working correctly.
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.0.5/firebase.js"></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/0.9.1/angularfire.min.js"></script>
Upvotes: 2