简体   繁体   中英

How to get a server response firebase?

How to get a response from the server?

I am doing a user update and I need to find out when the update was successful, how to do it? I want to refresh the page after a successful refresh.

// New data user

services.updateDataUser(userFind.id, {
    avatarUrl: user.avatarUrl.value,
    fullName: user.userFullName.value,
    userBio: user.userBio.value,
    password: newPassword(),
});

window.location.reload(); // if status updateDataUser - 200

// firebase api

updateDataUser = (id, user) => {
    firebase.firestore()
    .collection("users")
    .doc(id)
    .set({
        user: user
    }, {merge: true})
};

If I understand correctly, you want to only refresh the page after the user has been updated in Cloud Firestore. In that case you'll want to return a promise from ``, so that you can detect when the database write has completed:

services.updateDataUser(userFind.id, {
    avatarUrl: user.avatarUrl.value,
    fullName: user.userFullName.value,
    userBio: user.userBio.value,
    password: newPassword(),
}).then(function() {
  window.location.reload();
});

And

updateDataUser = (id, user) => {
  return firebase.firestore()
    .collection("users")
    .doc(id)
    .set({
        user: user
    }, {merge: true})
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM