Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore online rules simulator fails with custom claims

Using the firestore online security simulation with custom claims results in an error, but it works perfectly when deployed (while actually handling real requests). The error is:

Error: simulator.rules line [5], column [23]. Property admin is undefined on object.

I have confirmed that the user actually have the claim (by the admin SDK and by using the application I'm adding the rules to).

    match /{document=**} {
      allow write: if request.auth.token.admin;
        allow read;
    }

Code

Is this expected? Is the simulator broken or am I missing something? Not being able to use the simulator will be hard as I expect to use a few custom claims in my application.

like image 704
Jan Greger Hemb Avatar asked Jan 27 '23 00:01

Jan Greger Hemb


1 Answers

The rules simulator doesn't run with a real user from Firebase Authentication, but runs with the user you define within the simulator itself in the bottom left section of your screenshot.

So you'll need to specify the admin claim in the rules playground by selecting the Custom provider, and then editing the Auth token payload to include a token.admin property.

like image 56
Frank van Puffelen Avatar answered May 31 '23 12:05

Frank van Puffelen