0

I am trying to send the user to another page as soon as an update of the user's name has been completed. The problem is that I don't know when to call my location.replace function or how to using promises in this scenario. (username.value is the new username)

     //don't worry about the if statment, all it is doing is making sure that the element 
     //that stores the new username is not empty
     if(username.value != ""){
      db.collection("users").doc(doc.id).update({
        "name": username.value
      })  
      //How can I call this as soon as the username is set?
      //location.replace("../pages/homepage.html");
     }
Darrow Hartman
  • 4,142
  • 2
  • 17
  • 36

1 Answers1

1

You should find something here : https://firebase.google.com/docs/firestore/manage-data/add-data

But you should do something like this :

db.collection("users").doc(doc.id).update({
        "name": username.value
      }) 
      .then(() =>  location.replace("../pages/homepage.html"))
Emmanuel Demey
  • 2,158
  • 4
  • 18
  • 21