[英]Firebase / Angularfire 0.9 - Create new user and profile
要在Angularfire 0.9中创建新用户,我可以使用$ firebaseAuth服务和$ createUser方法。
但是,据我所知,此方法不会返回任何新用户凭据。 因此,如果我想向该用户添加配置文件,那么检索该用户Auth Data的最佳方法是什么,特别是“uid”,这样我就可以为我的新用户保存配置文件数据。 以下是我想要做的一个例子
var FIREBASEURL = "https://<my-firebase>.firebaseio.com"
var ref = new Firebase(FIREBASEURL);
$rootScope.authObj = $firebaseAuth(ref);
var newUser = {
email: "email@email.com",
password: "password",
displayName: "Display Name",
favFood: "Food"
};
$rootScope.authObj.$createUser(newUser.email, newUser.password).then(function() {
console.log("User created successfully!");
// Retrieve new Auth Data specifically uid
var newAuthData = ??????????
// Remove password from object and create user profile
delete newUser.password;
newUser.timestamp = Firebase.ServerValue.TIMESTAMP;
var userRef = new Firebase(FIREBASEURL + '/users/');
userRef.child( newAuthData.uid ).set(newUser);
}).catch(function(error) {
console.error("Error: ", error);
});
在0.9.1中,uid将与promise一起返回。 例如:
var FIREBASEURL = "https://<my-firebase>.firebaseio.com"
var ref = new Firebase(FIREBASEURL);
$rootScope.authObj = $firebaseAuth(ref);
var newUser = {
email: "email@email.com",
password: "password",
displayName: "Display Name",
favFood: "Food"
};
$rootScope.authObj.$createUser(newUser.email, newUser.password).then(function(authData) {
console.log(authData.uid); //should log new uid.
return createProfile(newUser, authData);
});
function createProfile(authData, user){
var profileRef = $firebase(ref.child('profile'));
return profileRef.$set(authData.uid, user);
};
这应该让你去。 关键是将返回的promise(在我的示例中为authData )传递给后续函数。
在0.9.0中,有必要调用身份验证方法以获取用户的uid。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.