0👍
✅
I think Doug Stevenson has already answered your question – to get the contents you just added you’ll need to query it from Firebase. But just to add a bit more, it looks like you’d probably like to wait until the data is added to change the route, in which case you may want to try something like this:
db
.collection("Users")
.doc(user.user.uid)
.set(this.data)
.then(function() {
console.log("Document successfully written!");
// After you know the data has been written, you can query it.
db.collection("Users").doc(user.user.uid).get().then((res) => {
// Log the data from the response
console.log(res.data())
resolve()
}).catch((err) => {
console.log(err)
reject(err)
})
// Then change the route.
this.$router.push("/welcome");
})
.catch(function(error) {
console.error("Error writing document: ", error);
});
0👍
It looks like your docRef
is a promise that comes from the return value of catch()
. That promise isn’t going to resolve with the contents of the document that was just added. Not even the promise returned by set() is going to give you the contents. If you want to query for the contents of that document, you’ll have to use get() on a reference to the document.
db.collection("Users").doc(user.user.uid).get(snap => {
// snap is a snapshot that contains the fields of the document
})
Source:stackexchange.com