【问题标题】:Firebase Auth createUserWithEmailAndPassword returns "There is no user record corresponding to this identifier. The user may have been deleted."Firebase Auth createUserWithEmailAndPassword 返回“没有与此标识符对应的用户记录。用户可能已被删除。”
【发布时间】:2021-04-20 18:35:12
【问题描述】:

每当我尝试通过调用 createUserWithEmailAndPassword 方法从 UI 注册新用户时,它都会返回“E {code:”auth/user-not-found”,消息:“没有与此标识符对应的用户记录。用户可能已被删除。", a: null}"。 不确定它是尝试登录还是存在其他问题。

这是我在 UI 上提交按钮的代码:

submit = () => {
    const un = document.getElementById('email-input').value;
    const pw = document.getElementById('password-input').value;

    if (this.pageType === 'login') {
        firebase.auth().signInWithEmailAndPassword(un, pw).then(res => {
            window.location.href = 'loggedin.html';
            console.log(res);
        })
    } else if (this.pageType === 'signup'){
        firebase.auth().createUserWithEmailAndPassword(un, pw).then(un, pw => {
          console.log(res);
        })

    }

有人有线索吗?

谢谢!

【问题讨论】:

    标签: javascript firebase firebase-authentication


    【解决方案1】:

    似乎pageType 变量即使在注册页面也等于“登录”,因为 auth/user-not-found 错误代码属于signInWithEmailAndPassword() 方法。在 if 语句之前添加 console.log() 语句以检测此情况。

    submit = () => {
        const un = document.getElementById('email-input').value;
        const pw = document.getElementById('password-input').value;
    
        // displays 'login' even at sign-up page.
        console.log(pageType); 
        
        if (this.pageType === 'login') {        
            firebase.auth().signInWithEmailAndPassword(un, pw).then(res => {
                window.location.href = 'loggedin.html';
                console.log(res);
            })
        } else if (this.pageType === 'signup'){
            firebase.auth().createUserWithEmailAndPassword(un, pw).then(un, pw => {
              console.log(res);
            })
    
        }

    【讨论】:

      【解决方案2】:

      更常见的方法是在同一个登录页面中有两个按钮:“注册”和“登录”,并为每个按钮附加不同的处理程序。

      例如在“Sign Up”按钮处理程序中调用firebase.auth().createUserWithEmailAndPassword,并在“Sign In”按钮处理程序中调用firebase.auth().signInWithEmailAndPassword

      拥有两个页面(登录和注册)并不能简化您的 UI。您仍然需要将这两个页面链接在一起,以防用户进入了错误的页面。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-20
        • 1970-01-01
        • 2019-06-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-22
        相关资源
        最近更新 更多