본문 바로가기
개발/Firebase

Exception from a finished function: Error: You must return a Promise in your transaction()-callback.

by dev_caleb 2022. 11. 17.
728x90

 

https://stackoverflow.com/questions/48623641/error-you-must-return-a-promise-in-your-transaction-callback

 

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