Lets assume we have a data structure similar to the one below, and using fan-out update we want to convert an invitation to a user.
- root
- users
- KC88nKzEqsx6AlPjrvp
- email : test1@yahoo.com
- uid: 19570b6c-afd0-xxxx-xxxx-650be04c5767
- KCAW6T_au2ROnJcaf85
- email : test2@yahoo.com
- uid: 22570b6c-afd0-xxxx-xxxx-650be04c5767
- KC88nKzEqsx6AlPjrvp
- invitations
- KCZndfnKzEqrtr6AlPjrvp
- email : test3@yahoo.com
- BYYAW6T_au2Rffeaf85
- email : test4@yahoo.com
- KCZndfnKzEqrtr6AlPjrvp
- users
Update code:
var update = {}
update[‘invitations/KCZndfnKzEqrtr6AlPjrvp’] = null
update[‘users/DDd83sx6AlPjrvp’] = {email:test3@yahoo.com, uid: 773492-afd0-344-4535-650be04c5767}
ref.update(update);
How can i write validate rules in Bolt, that will check if:
- Invitation for such email existed.
- The newly created user email is equal to email on invitation
- User uid is his actual id from auth object.