When working with my Vuex store, I encounter a problem in the action section.
The code snippet in question is as follows:
actionSignUp({ commit, dispatch }, form) {
commit("setStatus", "loading")
auth.createUserWithEmailAndPassword(form.email, form.password)
.then((response) => {
console.log(response.user.uid)
console.log("Successfull registered")
dispatch("actionCreateUserDocument", form, response.user.uid)
})
.catch((error) => {
commit("setStatus", "failure")
commit("setError", error.message)
})
},
actionCreateUserDocument({ dispatch }, form, uid) {
console.log(uid)
usersCollection.doc(uid).set({
email: form.email,
name: form.name,
courses: []
})
.then(() => {
console.log("Document successfully written!");
dispatch("actionFetchUserProfile", uid)
})
.catch((error) => {
console.error("Error writing document: ", error);
});
},
In the actionSignUp
function, when I call console.log(response.user.uid
, I get the correct value. However, when I pass the uid
to actionCreateUserDocument()
using
dispatch("actionCreateUserDocument", form, response.user.uid)
, the uid
appears undefined in the actionCreateUserDocument()
function.
What could be causing this issue?