简体   繁体   English

Android 中的 Firestore 权限被拒绝

[英]Firestore Permission Denied in Android

I'm self-learning to implement the Cloud Firestone service.我正在自学实现 Cloud Firestone 服务。

Right know, I just wanted to read the data in the cloud, but I get the following error: com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.对了,我只是想读取云端的数据,结果报错: com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or enough permissions。

Can anyone help me and tell me what I am doing wrong?谁能帮助我并告诉我我做错了什么? I don't seem able to pin point my error.我似乎无法指出我的错误。

Thanks in advance!提前致谢!

Permissions:权限:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    // This rule allows anyone on the internet to view, edit, and delete
    // all data in your Firestore database. It is useful for getting
    // started, but it is configured to expire after 30 days because it
    // leaves your app open to attackers. At that time, all client
    // requests to your Firestore database will be denied.
    //
    // Make sure to write security rules for your app before that time, or else
    // your app will lose access to your Firestore database
    match /{document=**} {
        allow read, write: if request.time < timestamp.date(2020, 3, 14);
    }
  }
}

ClientFragment.java: ClientFragment.java:

FirebaseFirestore databaseReference = FirebaseFirestore.getInstance();
Query query = databaseReference.collection("clients");

FirestoreRecyclerOptions<Client> options =
                new FirestoreRecyclerOptions.Builder<Client>()
                        .setQuery(query, snapshot -> {

                            Client client = snapshot.toObject(Client.class);
                            client.setId(snapshot.getId());

                            return client;
                        }).build();

        adapter = new FirestoreRecyclerAdapter<Client, ClientViewHolder>(options) {
            @Override
            public ClientViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                // Create a new instance of the ViewHolder, in this case we are using a custom
                // layout called R.layout.message for each item
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.list_item_client, parent, false);

                ClientViewHolder viewHolder = new ClientViewHolder(view);
                viewHolder.setOnDeleteClickedListener(mOnDeleteListener);
                viewHolder.setOnEditClickedListener(mOnEditListener);
                viewHolder.setOnItemClickListener(mOnItemListener);

                return viewHolder;
            }

            @Override
            protected void onBindViewHolder(ClientViewHolder holder, int position, Client model) {
                // Bind the Chat object to the ChatHolder
                // ...

                holder.Bind(model);
            }
        };


        binding.rvClient.setLayoutManager(new LinearLayoutManager(getActivity()));
        binding.rvClient.setAdapter(adapter);

Data:数据:

Image of Data in DataBase数据库中的数据图像

Your rules allow reads and write to any document, but only if the current date is earlier than March 14, 2020.您的规则允许读取和写入任何文档,但前提是当前日期早于 2020 年 3 月 14 日。

allow read, write: if request.time < timestamp.date(2020, 3, 14);

These initial set of default rules effectively "expired" over three months ago.这些初始的默认规则集在三个月前有效地“过期”。 You can change the date if you want (it should be obvious how to do this), or you can implement proper rules for your queries using what you learn in thedocumentation .您可以根据需要更改日期(应该很明显如何执行此操作),或者您可以使用您在文档中学到的内容为您的查询实施适当的规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM