Search code examples
google-cloud-firestorefirebase-securityfirebase-cli

Firestore emulator and debugging security rules


After some effort I have now my Firestore emulator setup and my first tests written using mocha! Great.

I understand it is not possible to debug security rules step by step but is there a way to log information or state to the console, directly from the security rules?


Solution

  • I believe there is an undocumented function in security rules that lets you write debug values to the log when running on the local emulator. Try the debug() function. It takes a parameter with value to log, and returns that same value to continue evaluation of the expression.

    match /users/{id} {
        allow read: if debug(id) == request.auth.uid;
    }