Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda