I am trying to set up a Firebase database that only I can write. So no user will have permission to write anything. But everyone will be able to read it.
However, I could not set up the rules for it. I have one admin user that I created using Email/Password login, and I know its UID. Let's say my UID is: dJrGShfgfd2
I tried these two methods, but they didn't allow me to write to database.
{
"rules": {
"events": {
".read": true,
".write": "auth.uid === 'dJrGShfgfd2'"
}
}
}
.
{
"rules": {
"users": {
"$user_id": {
".read" : true,
".write": "$user_id === 'dJrGShfgfd2'"
}
}
}
}
So how do I allow only one user with a specific UID to write anything to database?
Firebase users have a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in the project's user database, that can be updated by the user (iOS, Android, web).
When you create a database or storage instance in the Firebase console, you choose whether your Firebase Security Rules restrict access to your data (Locked mode) or allow anyone access (Test mode). In Cloud Firestore and Realtime Database, the default rules for Locked mode deny access to all users.
In the Firebase console, you can assign any of the basic roles (Owner, Editor, Viewer), the Firebase Admin/Viewer roles, or any of the Firebase predefined product-category roles.
This should work:
{
"rules": {
".read": true,
".write": "auth.uid === 'dJrGShfgfd2'"
}
}
Everyone in the world will be able to read the data, but only the user with UID dJrGShfgfd2
(and processes with administrative access) can write the data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With