我正在使用根据以下方案存储数据的数据库:
root:
currentTime
users:
<some user id>:
<value1>
<value2>
<some other id>:
<value1>
<value2>
我希望每个用户只能在各自的user_id文件夹下编辑值。 我的规则配置如下:
{
"rules": {
"currentTime": {
".read" : "auth != null",
".write" : "auth != null",
".validate" : "newData.isNumber() && newData.val() > 0"
},
"users": {
"$u_id": {
".read": "auth != null && $u_id === auth.uid",
".write": "auth != null && $u_id === auth.uid"
}
}
}
}
用户的任何读取或写入请求都会被拒绝权限,但是如果我删除了“ $ u_id === auth.uid”条件,那么一切似乎都可以正常工作。用户在我手动检查的user_id文件夹下写入值,该值与firebase用户选项卡中的uid相同,因此我不明白为什么该条件无法通过。 如果有帮助,这是我用于连接数据库的代码:
LD.LogMessage("Connecting to database");
authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
Firebase.Auth.Credential credential =
Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);
auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
if (task.IsCanceled) {
Debug.LogError("SignInWithCredentialAsync was canceled.");
return;
}
if (task.IsFaulted) {
Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
reference = FirebaseDatabase.DefaultInstance.RootReference;
userId = newUser.UserId;
LD.LogMessage("Successfully connected");
LD.canLoad = true;
});