私はFirebaseルールを使用してパーミッションを設定しています。ユーザと管理者を含む書き込み権限を許可するルールを設定する際に問題があります。以下はFirebaseルールを使用してユーザーおよび管理者に書き込み権限を与える方法を教えてください。
私は権限を設定しようとしていますデータベースされています。私は「ランキングに記述しようとしています
"rankings":{
"user":{
"$rankId": {
".read": true,
".write": "auth != null && ((root.child('users/' + auth.uid + '/rank').val() == $rankId) || root.child('admin/' + auth.uid).exists())"
}
}
}
/:これらは、このデータのための場所でのルールです
'rules': {
'rankings': {
'user': {
'userShortenedAuthId': { //user's rankings },
'anotherShortenedAuthId': { //another user's rankings }
}
},
'admin': {
'adminAuthId': true
},
'users': {
'userAuthId': {
'rank': 'userShortenedAuthId'
},
'anotherAuthId': {
'rank': 'anotherShortenedAuthId'
}
}
}
adminの下でログインしている間に「user/userShortenedId」と表示されましたが、Firebaseの許可が拒否されました。 (ユーザーがうまく動くとログインします)。エラーは 'rankings/user/$ rankId/.write'ルールのどこかにあります。私にとって混乱しているのは、管理者権限のために 'root.child(' admin/'+ auth.uid).exists())'ルールを使用していて、これもうまくいくようです。
ここに、許可エラーを生成するコードがあります。
firebase.database().ref('rankings/' + userShortenedAuthId).update({newPlayerKey:totalPlayers}))
.then(function(){
console.log('successfully updated user ranking');
})
.catch(function(err){
console.log('error updated user ranking', err);
});
トップレベルのルールノードがありません。それはあなたの実際のルールに存在していますか(あなたが投稿したスニペットから抜けていますか)?また、書き込みエラーを再現する最小限のコードを表示できますか? –
@FrankvanPuffelenトップレベルのルールが適所にあります。ここには含まれていません。私は、上記のエラーを生成したコードを追加します。 – tbone849
@FrankvanPuffelen NVM!私は間違ったfirebaseの参照URLに到達しようとしていることに気付きました。 'rankings/user /' + userShortenedAuthIdにする必要があります。 – tbone849