Here is a code snippet in vue.js
which includes an async function:
async up(id, point){
this.change = true
const pId = id + '-' + firebase.auth().currentUser.uid
db.collection('answer').doc(id).get().then((doc) => {
if(doc.data().user_id == firebase.auth().currentUser.uid){
alert("You can't vote for your own post")
return
}
})
db.collection('point').add({
answer_user: pId,
type: 'up',
}).catch(function(error){
console.error(error)
});
}
If the condition is true, it should show an alert and return. However, the return statement does not work as expected, and the function continues to execute and the next Firebase query is also executed.
So, how can we properly exit from the function?