0
votes

What I am doing

So, I connected two of my applications to the same database one is using real-time database and I successfully migrated some of the data from real-time database to cloud firestore using cloud functions and the other application is using cloud firestore.

The firebase auth is working fine for both the applications, first application is successfully fetching the data from real-time database

What my problem is

but the problem is the second app is unable to fetch the data from cloud firestore, so I successfully catch the exception and it says "com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions."

What I did to resolve

so from the exception I am able to figure out that it's a permission issue, so I changed my rules for the cloud firestore

Earlier firestore rule

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

Changed firebase rules

so I tried both of the below rule one by one to resolve the issue

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}

and

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

but unfortunately none of the above is able to solve the issue I am still getting the same exception even after publishing the new rules

UPDATE

screenshot of the current firestore rules

enter image description here

Kotlin code

class Toppers {
    private val firestore:FirebaseFirestore by lazy{
        FirebaseFirestore.getInstance()
    }

    private val toppersList = mutableListOf<Topper>()
    private val toppers = MutableLiveData<List<Topper>>()

    init {
        toppers.value = toppersList
    }

    fun getToppers():LiveData<List<Topper>>
    {
        firestore.collection("Toppers").get().addOnCompleteListener { task ->

            if(task.isSuccessful)
            {
                toppersList.clear()
                for(topper in task.result!!)
                {
                    Log.d("(Saquib)","data is fetched "+topper.get("name").toString())
                    toppersList.add(
                        Topper(topper.get("name").toString(),
                               topper.get("percentage").toString(),
                               topper.get("imgurl").toString(),
                               topper.get("resulturl").toString(),
                               topper.get("rollno").toString(),
                               topper.get("schoolname").toString(),
                               topper.get("session").toString(),
                               topper.get("stream").toString(),
                               topper.get("standard").toString())
                    )
                }
            }
            else
            {
                Log.d("(Saquib)","unable to fetch the data "+task.exception?.cause.toString())
            }
        }.addOnCompleteListener {
            toppers.value = toppersList
        }
        return toppers
    }
}

Android Logs

(Saquib): unable to fetch the data io.grpc.StatusException: PERMISSION_DENIED: Missing or insufficient permissions.

can anyone please help me out, i'll be really thankful to you

1
i very much doubt if its firebase security rule issues, since the default rule says you have read and write access on any documents, which simply means you are kind of admin. - Jithin
Hi Kevin, Thanks for your response i have added the screenshot of the current firestore rules in my question as per your instruction, but unfortunately i am still getting the same exception - Saquib Siddique
Where is your logcat error? Are you sure you are getting problem in Read Write? You are may be trying to get wrong data. - Pratik Butani
Hi Pratik, Thanks to come forward, i have added the android logs along with the kotlin code please find them under the updates - Saquib Siddique

1 Answers

0
votes

Go in Database -> Rules ->

 allow read, write: if false; to true;

But be warned, this means there is no security at all to your firestore database