You can collaborate by hashing the email address of the user with whom you want to share a specific piece of data and store it in the permission field.
For example, start with the path / items / item 1, which belongs to "user1":
{ "items": { "item1": { "data": "foobar", "permissions": { "user1": true } } } }
You have set up security rules for data as follows:
{ "rules": { "items": { "$item": { ".read": "data.child('permissions').hasChild(auth.uid)", ".write": "data.child('permissions').hasChild(auth.uid)" } } } }
Now that "user1" wants to share "item1" with "user2", they just write the value "user2" and set it to true under the permission key. You can expand the structure of the Permissions key to the extent you want (for example: co-authors can only read, but the owner can read and write, etc.).
In practice, you can, for example, use user address hashes. Also check out Simple Login for an easy way to authenticate your users (after authentication, the auth variable used in the above security rules is automatically set for you).
Anant source share