Since firebase runs async, how could i run a set query after receiving data from get query and checking if it exists before set?

```
  var db = firebase.firestore();
  db.settings({});
  const usersRef = db.collection('users').doc(user.uid)

  usersRef.get()
    .then((docSnapshot) => {
      if (!docSnapshot.exists) {
        usersRef.set({
          name: '',
          email: '',
        })
          .then(function() {
            console.log("Document successfully written!");
          })
          .catch(function(error) {
            console.error("Error writing document: ", error);
          });
      }
    });

```

Thanks in advance