Firebase数据库Swift的权限被拒绝

时间:2020-06-18 18:40:33

标签: ios swift firebase google-cloud-firestore firebase-security

我不断收到此错误:当我尝试写入Firestore数据库时,缺少权限或权限不足。我用它来保存用户的名字/姓氏;但是,我的规则是:

findViewById(R.id.sendBtn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO: in a click it will gather all data from the user, turn it into a json object, and will send it to the DB;
                nameOfProduct = ((EditText)findViewById(R.id.etNameOfPr)).getText().toString();
                serialOfProduct = ((EditText)findViewById(R.id.etSerialOfPr)).getText().toString();
                priceOfProduct = ((EditText)findViewById(R.id.etPriceOfPr)).getText().toString();

                try {
                    productJson(nameOfProduct, serialOfProduct, priceOfProduct, getGenderRB(), uriList, getColorsCB(), getSizeCB(), new JSONMadeListener() {
                        @Override
                        public void onJSONMade(JSONObject object) {
                            try {
                                SSLContext.getInstance("TLSv1.2");
                            } catch (NoSuchAlgorithmException e) {
                                e.printStackTrace();
                            }
                            try {
                                ProviderInstaller.installIfNeeded(getApplicationContext());
                            } catch (GooglePlayServicesRepairableException e) {
                                e.printStackTrace();
                            } catch (GooglePlayServicesNotAvailableException e) {
                                e.printStackTrace();
                            }
                            new SendProductJsonTask().execute("https://10.0.2.2:4000/products/add",object.toString());
                        }
                    });
                } catch (JSONException e) {
                    e.printStackTrace();
                }

此外,我使用相同的数据库来保存其他内容,效果很好。仅此一项不起作用。我不知道为什么。

以下是写入firestore的代码:

service cloud.firestore {
  match /databases/{database}/documents {
    match /countData/{anything=**} {
      allow read, write;

    }
  }
}

非常感谢您!

1 个答案:

答案 0 :(得分:2)

您的规则正在保护countData集合,但是您的代码正在尝试查询用户集合。规则必须始终与查询匹配。

    match /users/{anything=**} {
      allow read, write;
    }