Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 是否可以在Firebase中为匿名身份验证设置displayName_Angularjs_Firebase_Angularfire - Fatal编程技术网

Angularjs 是否可以在Firebase中为匿名身份验证设置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属性。据我所知,你自己并没有

我正在使用Firebase通过AngularFire的简单登录和匿名登录方法,我想知道是否还有其他方法可以设置从中返回的用户对象的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");

这确保了只有经过正确身份验证的用户才能修改自己的显示名称。

这实际上是一种非常合理的方法,感谢您的建议!这实际上是一个相当合理的方法,谢谢你的建议!