0👍
this seem to be the most practical method:
Tying the users node to the buildings:
Template:
<p>Name: <input type="text" v-model="newBuilding.name"></p>
<p>Address: <input type="text" v-model="newBuilding.address"></p>
Data:
data () {
return {
newBuilding: {
name: '',
address: '',
ownerID: '',
}
}
},
Methods:
addBuilding: function () {
// get current user from firebase
let userId = firebase.auth().currentUser.uid;
// create a random pushkey but without pushing it yet
let buildingKey = buildingsRef.push().key
// set the user.uid as building data child "ownerId" value, (the other data nodes where hydrated from the <template>
this.newBuilding.ownerID = userId;
// SET THE NEW BUILDING
buildingsRef.child(buildingKey).set(this.newBuilding);
// SET THE BUILDING PUCHKEY ON A CHILD NODE ON THE **USERS** NODE
usersRef.child(userId).child('isAdmin').child(buildingKey).set(true);
}
I hope this does it for you.
Follow more questions on this topic here:
What is the best practice to write the rules of Firebase in a situation like this?
Is it possible to define a variable on the firebase database references path?
- [Vuejs]-Input field unable to change model when component and model are dynamically created
- [Vuejs]-Access to DOM element with Vue method
Source:stackexchange.com