0
votes

I'm self-learning to implement the Cloud Firestone service.

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.

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:

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

1

1 Answers

0
votes

Your rules allow reads and write to any document, but only if the current date is earlier than March 14, 2020.

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 the documentation.