As I venture into using firestore for the first time, I'm in the process of creating a registration page with vue. One crucial step before adding a new user to the database is to validate if the provided username already exists. If it does not exist, then proceed with creating a new user.
I have successfully implemented code to add a new user to the database. However, I am encountering difficulties in checking the availability of the username before adding a new user. This is what I have tried so far:
db.collection("Users")
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
if (this.username === doc.data().username) {
usernameExist = true;
}
});
});
Open to any suggestions or advice from experienced developers?