Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
Missing or insufficient permissions firestore although it works on rules play ground

I have added some security rules to my project and tested them in rules playground everything seems to be working perfect but when I try to retrieve the same doc using same UID from my website it throws error: "FirebaseError: Missing or insufficient permissions".

Refrence to collection:

dbRef = db.collection("organization").doc(organization).collection(course).doc(courseId).collection("meetings");

This are the snapshot of my code:

function causing error

Updated security rules

Note: I have already tested the security rules in rules playground with different uids and paths. And it worked perfectly.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

dbRef = db.collection("organization").doc(organization).collection(course).doc(courseId).collection("meetings"); This query attempts to fetch all documents under meeting collection.

There is a possibility that the above query will fetch documents where designation != 'Teacher' && courseId != course;

Therefore it will fail.

From firestore rules docs

if you have this rule:

match /stories/{storyid} {
  // Only the authenticated user who authored the document can read or write
  allow read, write: if request.auth != null && request.auth.uid == resource.data.author;
}

and this request db.collection("stories").get().

The query fails even if the current user actually is the author of every story document. The reason for this behavior is that when Cloud Firestore applies your security rules, it evaluates the query against its potential result set, not against the actual properties of documents in your database. If a query could potentially include documents that violate your security rules, the query will fail.

the following query succeeds, because it includes the same constraint on the author field as the security rules:

var user = firebase.auth().currentUser;
db.collection("stories").where("author", "==", user.uid).get()

NB: playground can only test for document gets (not list collection).

Possible solution. You can write your query in such a way that it can never return the wrong document.

Something like this. When a student is enrolled to take a meeting (or course), add his uid to that meeting's document. doc = {student_ids = [uidofstudent1, uidOfStudent2, ...]}.

Then you can query like this:

db
    .collection("organization")
    .doc(organization)
    .collection(course)
    .doc(courseId)
    .collection("meetings")
    .where('student_ids', arrayContains: studentUid);

Your firestore rules can be something like this:

match /organisation/{org}/{course}/{courseId}/meetings/{meet=**} {
  allow read: if request.auth.uid in resource.data.student_ids || 
    isTeacher(request.auth.uid);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda