答案 0 :(得分:1)
如果您希望用户只能使用电子邮件,电话和用户名字段,则可以使用与此类似的规则:
{
"rules": {
"Users": {
"$user_id": {
//Every authenticated user can read
".read": "auth != null ",
// grants write access to the owner of this user account
// whose uid must exactly match the key ($user_id)
".write": "$user_id === auth.uid",
//This line says the new data must have ATLEAST these children
".validate": "newData.hasChildren(['email','phone', 'username'])",
//You can add individual validation for email, phone and username here
"email": { ".validate": true },
"phone": { ".validate": true },
"username": { ".validate": true },
//This rule prevents validation of data with more child than defined in the 2 lines above (or more if you specify more children)
"$other": { ".validate": false }
}
}
}
}
有关验证数据的详细信息,请查看the firebase security docs。