2014-03-29 41 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

相關問題