This is my code:
let curId;
if (!user) {
  db.collection("users")
    .add({
      name: name,
    })
    .then((doc) => curId = doc.id)
    .catch((err) => console.error(err));
} else {
  curId = user.id;
}
console.log(curId); <-- I need curId here
Currently I get undefined for curId because I am not waiting for the async code to finish running. What is the best way to achieve this?
Some approaches I've thought of:
- Use awaitinstead of.thenbut I feel like this may look less organized/messy with thetryandcatch
- I could also add what I want to do with curIdin both theifand theelsestatement but I'd rather not write redundant code
 
    