Here's my database structure:
Clients:
employee1emailaddress
employee2emailaddress
Employees:
employee1emailaddress
employee2emailaddress
allClients:
client1phonenumber
client2phonenumber
I want to make a security rule to limit the authenticated user to read and write from nodes associated to their email address
For example:
the employee who has the email address of employee1emailaddress
can only read from and write to the nodes that has their email addresses as the key
How to make that possible ? and thanks in advance..
To change the rulles you can go to the firebase project area Database on the left menu and then rules on the blue menu. However I need to mention that if you are doing a firebase deploy you WILL OVERWRITE these rulles with the contents of database.
Firebase Security Rules work by matching a pattern against database paths, and then applying custom conditions to allow access to data at those paths. All Rules across Firebase products have a path-matching component and a conditional statement allowing read or write access.
To be able to let authenticated users access the database, we will need to use Firebase's Admin SDK. This framework will give us access to an API to verify authenticated users and pass requests to our database. We will be saving users' data using Firebase's Realtime Database.
The short answer is yes: by authenticating your users and writing security rules, you can fully restrict read / write access to your Firebase data. In a nutshell, Firebase security is enforced by server-side rules, that you author, and govern read or write access to given paths in your Firebase data tree.
I would recommend not associating data with a user's email address. You should use their UID instead:
{
"rules": {
"$uid": {
".read": "auth !== null && auth.uid === $uid",
".write": "auth !== null && auth.uid === $uid"
}
}
}
This will only allow users to read and write from a directory in your database where the key is their UID.
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