首页 文章

如果现有帐户尝试在Firebase Firestore中注册会怎样?

提问于
浏览
0

每当新用户在Firebase Auth(用户名和密码)中注册时,我在Firestore中创建一个具有相同 uid 的帐户 .

如果现有帐户出错路线并尝试注册而不是登录,会发生什么?我不想覆盖帐户中已有的信息,默认值字段应该仅在创建新帐户时设置 .

我知道我可以在Firestore中获取以查看与该ID相关联的帐户是否存在,但在此之前,如果使用现有 username 调用方法 createUserWithEmailAndPassword ,Firebase Auth是否会出错?如果是这样,我可以告诉用户该帐户已经存在,因此,将他/她重定向到登录活动 .

1 回答

  • 0

    根据此文档,现有帐户存在错误Firebase docsThe email address is already in use by another account. ”如果您需要从firebase请求返回的错误代码:

    {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "invalid",
        "message": "EMAIL_EXISTS"
       }
      ],
      "code": 400,
      "message": "EMAIL_EXISTS"
     }
    }
    

    但总的来说,是的,你看到一个例外 . What actually you might need 这是你的代码中你可以通过错误回调中的对象处理它,代码为“ auth/email-already-in-use ”谁错误对象是

    firebase.auth().createUserWithEmailAndPassword(this.email, this.password).then(
              (user) => {
              // do your
              },
              (err) => {
                if(err.code === 'auth/email-already-in-use');
                  alert('Oops. ' + err.code)
              }
            );
    

相关问题