Angularjs 是否可以在Firebase中为匿名身份验证设置displayName
我正在使用Firebase通过AngularFire的简单登录和匿名登录方法,我想知道是否还有其他方法可以设置从中返回的用户对象的displayName属性Angularjs 是否可以在Firebase中为匿名身份验证设置displayName,angularjs,firebase,angularfire,Angularjs,Firebase,Angularfire,我正在使用Firebase通过AngularFire的简单登录和匿名登录方法,我想知道是否还有其他方法可以设置从中返回的用户对象的displayName属性 $scope.loginObj.$login('anonymous').then(function(user) { user.displayName // This is an empty string } 我想设置displayName并将其保存回Firebase,以便用户可以显示为displayName属性。据我所知,你自己并没有
$scope.loginObj.$login('anonymous').then(function(user) {
user.displayName // This is an empty string
}
我想设置displayName并将其保存回Firebase,以便用户可以显示为displayName属性。据我所知,你自己并没有写任何简单的登录。似乎只有在您使用电子邮件/密码身份验证和
$scope.loginObj.$createUser('name','password')
时才会写入,但是,您可以这样做以获得相同的行为
$scope.loginObj.$login('anonymous').then(function(user) {
if (!user) return;
$scope.userRef = (new Firebase('<Your Firebase>.firebaseio.com/users/')).child(user.uid);
$scope.userRef.child('displayName').on('value', function (snapshot) {
user.displayName = shapshot.val();
});
});
// Then elsewhere in your code, set the display name and user.displayName will be updated automatically
$scope.userRef.child('displayName').set("DISPLAY NAME");
这确保了只有经过正确身份验证的用户才能修改自己的显示名称。您描述的方式不可能做到这一点,但是,您可以这样做以获得相同的行为
$scope.loginObj.$login('anonymous').then(function(user) {
if (!user) return;
$scope.userRef = (new Firebase('<Your Firebase>.firebaseio.com/users/')).child(user.uid);
$scope.userRef.child('displayName').on('value', function (snapshot) {
user.displayName = shapshot.val();
});
});
// Then elsewhere in your code, set the display name and user.displayName will be updated automatically
$scope.userRef.child('displayName').set("DISPLAY NAME");
这确保了只有经过正确身份验证的用户才能修改自己的显示名称。这实际上是一种非常合理的方法,感谢您的建议!这实际上是一个相当合理的方法,谢谢你的建议!