2014-03-29 39 views
0

我正在通过匿名登录方法使用Firebase的通过AngularFire的简单登录,并且我想知道是否无论如何设置从是否有可能在Firebase中为匿名身份验证设置displayName

返回的用户对象的displayName属性
$scope.loginObj.$login('anonymous').then(function(user) { 
    user.displayName // This is an empty string 
} 

我想设置displayName并将其保存回Firebase,以便用户可以显示为该displayName属性。据我所知,你自己实际上没有写任何简单的登录。它似乎是唯一一次写入是,如果你使用的东西如电子邮件/密码认证和使用$scope.loginObj.$createUser('name', 'password')

回答

2

这是不可能的你描述的方式,但是,你可以做到这一点,以获得相同的行为。

$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"); 

你甚至可以回本了简单的安全规则:

{"rules": 
    "users": { 
    "$uid" { 
     ".read": true, 
     ".write": "$uid == auth.uid' 
    } 
    } 
} 

这将确保只有一个正确验证用户可以修改自己的显示名称。

+0

这实际上是一个非常合理的方法,感谢您的建议! – MAP

相关问题