By default, Firebase sets the rules for users to authenticate before writing or reading operations. We can go to our project in Firebase console and choose the Database option in the left-hand options panel and go to the Rules tab in the Main panel. The default rules are as follows:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
The following screenshot shows the default security configurations for any Realtime Database project:
Firebase offers a unique way to examine rules in the simulator. In the right-hand corner of the Firebase console's Main window, you will notice a blue button labelled as SIMULATOR, click on it to have a perceptible familiarity. Now we can see that there are two checkboxes and one input field to enter the URL and a toggle button indicating Authenticated. If you toggle it towards the right side, you will see a drop-down allowing you to choose the security provider, and it will also show UID and auth token payload. When we click on the RUN button, it will show the possible responses.
The following screenshot shows the Simulator in a default state:
If we press the RUN button, the simulator assumes that the user continues not-authenticated, and it will return a Simulated read denied error.
The following screenshot illustrates the not-authenticated user's state:
If you want to allow the user to access the database without authentication then you need to set the rules to true.
Since now we know what a simulator is, let's check what happens when we push the toggle button and choose a provider:
It will grant the access to the database. Likewise, we can run the test on the write operation and understand what happens behind the screen.