In my Vue App, I designed a registration form to automatically create a Firestore document linked to the User UID with a unique document ID. Although the user creation process is successful, the document creation fails without showing any errors in the console even after using the catch() error method.
register() {
//Generate pin
function generateQuickGuid() {
return Math.random()
.toString(36)
.substring(2, 15);
}
let ref = fs.doc(generateQuickGuid());
ref.get().then(doc => {
if (doc.exists) {
console.log("Pin Exists");
} else {
console.log("pin doesn't exist");
// then add user to firestore
if (
this.email &&
this.password &&
this.displayName &&
this.category
) {
auth
.createUserWithEmailAndPassword(this.email, this.password)
.then(cred => {
ref
.set({
Name: this.displayName,
address: "close to understanding, firebase, auth",
phone: "09808763987",
category: this.category,
alias: pin,
user_id: cred.user.uid
})
.catch(e => {
console.log(e);
});
console.log("User Added");
})
.catch(error => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
console.log(errorCode, errorMessage);
});
}
}
});
}