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

202
Visualizações
firebase rules how to make user can read only his data

I use firebase 8.10.0 white Vue Js.

I use only Google as a provider for authentication and I want user to read-only his data, so i use firestore rules:

my rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    
    match /users/{id} {
      allow read: if request.auth.uid == id;
    }
    
  }
  
}

and this is how i get the data:

...

let ref = firebase.firestore().collection("users");

// .where("__name__", "==", uid) or
ref.doc(uid).get().then((doc) => {
  this.data = [{id: doc.id}];
})
// working well

ref.get().then((doc) => {
  doc.forEach((doc) => {
    this.data.push({ id: doc.id });
  });
})
// err: Uncaught (in promise) FirebaseError: Missing or insufficient permissions.

...

can I do this and ? how can i fix that? : my bad :')

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

0

You are trying to query the whole users collections but your security rules allow a user to read a document with user's UID as doc ID. Security rules don't filter out documents so if you are trying to get current user's document only then try using get() on a DocumentReference:

// add .doc(<userId>)
let ref = firebase.firestore().collection("users").doc(currentUserId);

ref.get().then((doc) => {
  this.data = [{id: doc.id}];
})
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