Firebase Fan-out update validation in Bolt

Viewed 104

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
    • invitations
      • KCZndfnKzEqrtr6AlPjrvp
        • email : test3@yahoo.com
      • BYYAW6T_au2Rffeaf85
        • email : test4@yahoo.com

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:

  1. Invitation for such email existed.
  2. The newly created user email is equal to email on invitation
  3. User uid is his actual id from auth object.
0 Answers
Related