【问题标题】:Auth Username (displayName) validation in FirebaseFirebase 中的 Auth 用户名 (displayName) 验证
【发布时间】:2021-10-04 00:36:46
【问题描述】:

我正在制作一个聊天应用程序,并且我正在使用 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;
        });
    },
  },

提前谢谢你。

【问题讨论】:

    标签: javascript firebase vue.js authentication firebase-authentication


    【解决方案1】:

    我不建议在用户的displayName 中存储username。在这种情况下,验证唯一用户名会很困难。

    我宁愿建议将用户名存储在其中一个 Firebase 数据库中,然后使用云函数或前端代码更新 displayName。至少应该在数据库上进行验证,因为您可以编写规则,使重复的​​username 是不可能的。

    Here 是一个链接,您可以在其中找到各种解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 2018-07-22
      • 2018-03-10
      • 2022-01-16
      • 1970-01-01
      • 2020-01-13
      相关资源
      最近更新 更多