Esta es la estructura básica de la base de datos de Firestore que estoy usando. editar: todos los nombres están en minúsculas
Las reglas que quiero son
1 funciona según lo previsto 2 no
match /databases/{database}/documents { match /hostels/{hostelId} { allow read, write: if request.auth.uid != null; match /rooms/{roomId} { allow read, write: if exists(/databases/$(database)/documents/ hostels/$(hostelId)/admins/$(request.auth.uid)); allow read: if exists(/databases/$(database)/documents/ hostels/$(hostelId)/rooms/$(roomId)/residents/$(request.auth.uid)); } } }mientras leo salas como residente me sale un error
Null value error. for 'list' @ L49También probé con get () leyendo un campo booleano de documento residente y sin suerte.
¿Qué estoy haciendo? ¿Existe un límite para la profundidad del argumento de ruta de acceso() y get()? Cualquier ayuda sería muy apreciada
el código que uso para consultar habitaciones por residente es
let q = collection(this.hostelCollection, this.residentSnap.get('hostel_id'), "rooms") let docs = await getDocs(q);el documento de residente tiene un campo hostel_id que contiene la identificación del albergue
Intente agregar una sola declaración de permiso de allow read y refactorizar las reglas como se muestra a continuación:
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /hostels/{hostelId} { allow read, write: if request.auth.uid != null; match /rooms/{roomId} { function isAdmin() { return exists(/databases/$(database)/documents/hostels/$(hostelId)/admins/$(request.auth.uid)); } function isResident() { return exists(/databases/$(database)/documents/hostels/$(hostelId)/rooms/$(roomId)/residents/$(request.auth.uid)); } allow read: if isAdmin() || isResident(); allow write: if isAdmin(); } } } }