Это моя структура данных firebase:
![](https://i.stack.imgur.com/ZRHcO.png)
Здесь, в папке Posts-> PIN-> postsIds-> phone 123456789, только он и администраторы могут писать в этот узел postsId.
Как написать такие правила безопасности?
Мое текущее правило безопасности
"rules": {
"Admins": {
".read": "auth != null",
".write": "auth != null",
},
"All_Posts": {
".read": true,
".write": "auth.uid != null"
},
"Posts": {
".read": true,
".write": "auth.uid != null"
},
"Users": {
".read": "auth.uid != null",
".write": "auth.uid != null"
}
}
Обновить правила После добавления настраиваемой заявкикак
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sellerCustomClaim = functions.database.ref('/Users/{userNumber}')
.onCreate((data, context) => {
const sellerNumber = context.params.userNumber;
const uid = context.auth.uid;
const customClaims = {
number: sellerNumber,
};
console.log(`Uid: ${uid}, number: ${sellerNumber}`);
console.log(`before Seller number: ${sellerNumber}`);
return admin.auth().setCustomUserClaims(uid, customClaims).then(() => {
console.log(`claim added!`);
})
.catch(error => {
console.log(error);
})
});
Я добавил админ true таким же образом
const customClaims = {
admin: true,
};
И я написал свои сообщения как
"Posts": {
"$pin": {
"$pid": {
".read": true,
".write": "auth.token.admin === true || data.child('phone').val() === auth.token.phone"
}
}
},
, чтобы каждый мог прочитать этоно только админ и если номер почтового телефона и номер текущего пользователя совпадают.
Как это сделать?