개발/Firebase
Exception from a finished function: Error: You must return a Promise in your transaction()-callback.
dev_caleb
2022. 11. 17. 01:10
728x90
Error: You must return a Promise in your transaction()-callback
My script is throwing the following error when returning the result of the assync firestore set function: You must return a Promise in your transaction()-callback. According to firebase documen...
stackoverflow.com
stackoverflow에 나와 있던 코드
return db
.runTransaction(t => {
t.set(docRef, chat, {merge:false});
return Promise.resolve(); // Add this line.
})
.then( doc => {
response.send();
})
.catch(err => {
...;
})
내가 작성한 코드
function givePoint(uid,userMap, userHistoryMap){
const userRef = admin.firestore().collection("Users").doc(uid);
return admin.firestore().runTransaction(t => {
//point 추가
t.set(userRef, userMap, { merge: true } );
//userCollection에 history 추가
t.set(userRef.collection('point_history').doc(), userHistoryMap);
return Promise.resolve();
});
}
728x90