我正在制作一个聊天应用程序,我正在使用firebase进行身份验证。目前,允许两个或多个用户使用相同的用户名(displayName)。我想添加验证来防止这种情况。以下是注册函数。我使用的是Vue.js,但对于非Vue用户来说,它也应该很容易理解。
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;
});
},
},
提前谢谢你。
发布于 2021-07-28 17:49:44
我不建议在用户的displayName
中存储username
。在这种情况下,对唯一用户名的验证将很困难。
我更推荐将用户名存储在其中一个Firebase数据库中,然后使用云函数或前端代码来更新displayName
。至少应该在数据库上进行验证,因为您可以用一种复制username
不可能的方式来编写规则。
Here是一个链接,您可以在其中找到各种解决方案。
https://stackoverflow.com/questions/68557529
复制相似问题