Reputation: 355
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?
Upvotes: 13
Views: 12882
Reputation: 23
In version 2:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read: if true;
allow write: if request.auth.uid == "dJrGShfgfd2";
}
}
}
Upvotes: 0
Reputation: 598837
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.
Upvotes: 27