Правила хранения Firebase «неавторизованы» - PullRequest
1 голос
/ 16 июня 2019

Вот мои правила хранения:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /auction-images/{auctionId} {
      allow read;
      allow write: if request.auth != null && request.resource.size < 1 * 1024 * 1024
                   && request.resource.contentType.matches('image/.*');

    }
  }
}

Как видите, я хотел бы разрешить все чтения с auction-images/{auctionId}. Когда я попытался запустить симулятор, он работал как ожидалось.

Однако, когда я запускаю свое приложение и пытаюсь загрузить изображение, оно печатает эту ошибку:

code: "storage/unauthorized"
code_: "storage/unauthorized"
message: "Firebase Storage: User does not have permission to access 'auction-images/NVOi2jGlfDA5huPUzjSA'."
message_: "Firebase Storage: User does not have permission to access 'auction-images/NVOi2jGlfDA5huPUzjSA'."
name: "FirebaseError"
name_: "FirebaseError"
serverResponse: "{↵  "error": {↵    "code": 403,↵    "message": "Permission denied. Could not perform this operation"↵  }↵}"
serverResponse_: "{↵  "error": {↵    "code": 403,↵    "message": "Permission denied. Could not perform this operation"↵  }↵}"

Несмотря на то, что я опубликовал изменения в моих правилах, они, похоже, не вступают в силу. Чего мне не хватает?

Вот код, который выдает мне ошибку:

this.firestorage.storage.ref(`auction-images/${this.recentAuctions[0].uuid}`).list().then(res => {
    console.log(res)
  })
  .catch(err => {
    console.log(err);
  });

1 Ответ

0 голосов
/ 16 июня 2019

Оказывается, мои правила были неправильными.Я обновил их так:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /auction-images/{auctionId}/{image} {
      allow read;
      allow write: if request.auth != null && request.resource.size < 1 * 1024 * 1024
                   && request.resource.contentType.matches('image/.*');
    }
  }
}

Я думал, что match /auction-images/{auctionId} позволит написать правила для всей папки, но мне пришлось добавить /{image} для правил, применимых к изображениям.внутри.

...