I am wrapping some updates inside a transaction to make them atomic. For example, when a user updates his displayName (which is stored inside a users collection), displayName of firebase auth is also to be updated. I want to do both of these updates inside a transaction. All the examples I have seen so far for transactions is about updating some document data inside some collection. How about wrapping auth functions inside a transaction or associating them with existing transactions? Is it possible?
I have this snippet in place:
db.runTransaction((transaction)=>{
return transaction.get(displayNameCheckRef).then((snapshot)=>{
var newDisplayName = this.state.name;
if(snapshot.empty){
transaction.set(currentUserRef, {displayName:newDisplayName});
}
});
})
.then((newDisplayName)=>{
console.log("display name changed to " + newDisplayName);
})
.catch((error)=>{
console.log("transaction error.");
console.log(error);
});
Now I want to associate the below updateProfile function with the transaction above. How do I do this?
user.updateProfile({
displayName: this.state.name
}).then(() => {
//do some stuff here
});
Thanks a lot!