I am making a chatting app and I am using firebase for authentication. Currently, two or more users are allowed to have the same username (displayName). I want to add validation to prevent this. Following is the signup function. I am using Vue.js, but it should be easy to understand for non-Vue users as well.
methods: {
signup(e) {
e.preventDefault();
firebase
.auth()
.createUserWithEmailAndPassword(this.email, this.password)
.then((result) => {
result.user.updateProfile({
displayName: this.username,
});
this.email = "";
this.password = "";
this.$emit("closemodal");
})
.catch((error) => {
this.error = error.message;
});
},
},
Thank you in advance.