Search code examples
firebasegoogle-cloud-firestoregoogle-cloud-storagefirebase-security

Firebase Storage rules that query data from Firestore


I need to check a document's data in Firestore to allow someone to view an image in Firebase Storage. Is this possible?


Solution

  • Edit: it is now possible to query Firestore from Storage security rules. You can read about it here and read the documentation here.


    Original answer:

    It is currently not possible to access Cloud Firestore documents directly from Cloud Storage rules. You have two options:

    1. Somehow use Firebase Authentication custom claims on the user account to determine if a user should be able to access a file.
    2. Use some backend code (maybe a Cloud Functions HTTP trigger) that the user accesses to download the file if the conditions are met.

    In either case, you will need some backend code that checks and sets the appropriate data.