我的问题是我该如何进行这项工作。
rules_version: "2";
service cloud.firestore { //define used service
match /databases/{databases}/documents { //not a specific database (important)
match /{document == request.auth.token.sub} { //how can this work?
//some more conditions and allows
}
}
}
用户应该能够访问许多数据库,但是所有文档都是以用户UID命名的,即UID,即request.auth.token.sub。 UID和文档名称应匹配。如何用firebase-security-rules-language编写此代码?
修改
这是我的工作解决方案:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow create: if request.auth != null;
}
match /{database}/{userId}/{document=**} {
allow read, update, delete: if request.auth != null &&
request.auth.uid == userId;
}
}
}
答案 0 :(得分:0)
是的,但是您使用了错误的字段和错误的测试。从firestore的文档中,您希望它更像:
[error] /Users/nicolae.marasoiu/proj/data-availability-global-topic-conveyor/src/main/scala/com/ovoenergy/globaltopics/serdes/AvroFormatImplicits.scala:8:15: value const is not a member of object com.sksamuel.avro4s.SchemaFor
[error] SchemaFor.const(new Schema.Parser().parse(getClass.getResourceAsStream(hasSchema.resourcePath)))
[error] ^
[error] /Users/nicolae.marasoiu/proj/data-availability-global-topic-conveyor/src/main/scala/com/ovoenergy/globaltopics/serdes/AvroFormatImplicits.scala:11:26: not enough arguments for method apply: (implicit evidence$1: com.sksamuel.avro4s.Encoder[T], implicit evidence$2: com.sksamuel.avro4s.Decoder[T])com.sksamuel.avro4s.RecordFormat[T] in object RecordFormat.
[error] Unspecified value parameter evidence$2.
[error] RecordFormat.apply[T](AvroSchema[T](readSchema))
[error] ^
[error] /Users/nicolae.marasoiu/proj/data-availability-global-topic-conveyor/src/main/scala/com/ovoenergy/globaltopics/serdes/SerdeProvider.scala:29:37: org.apache.avro.Schema does not take parameters
[error] val schema = SchemaFor[T].schema(DefaultFieldMapper)
[error] ^
[error] /Users/nicolae.marasoiu/proj/data-availability-global-topic-conveyor/src/main/scala/com/ovoenergy/globaltopics/serdes/SerdeProvider.scala:37:70: no arguments allowed for nullary method build: ()com.sksamuel.avro4s.AvroOutputStream[T]
[error] val os = AvroOutputStream.binary[T].to(output).build(schema)
[error] ^
[error] four errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 17 s, completed 28-Jul-2020 19:42:21
[IJ]sbt:global-topic-conveyor>
请参阅:https://firebase.google.com/docs/firestore/security/rules-conditions
答案 1 :(得分:0)
查看content-owner access上的Firebase文档,其中包含Firestore的以下示例:
service cloud.firestore {
match /databases/{database}/documents {
// Allow only authenticated content owners access
match /some_collection/{userId}/{documents=**} {
allow read, write: if request.auth != null && request.auth.uid == userId
}
}
}