简体   繁体   中英

Firebase Auth createUserWithEmailAndPassword returns "There is no user record corresponding to this identifier. The user may have been deleted."

Whenever I try to sign up a new user from the UI by calling createUserWithEmailAndPassword method, it returns "E {code: "auth/user-not-found", message: "There is no user record corresponding to this identifier. The user may have been deleted.", a: null}". Not sure if it tries to sign in instead or if there is some other issue.

Here is my code for the Submit button on the 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);
        })

    }

Does anyone have any clues?

Thank you!

It seems that the pageType variable is equal to 'login' even at the signup page because the auth/user-not-found error code belongs to the signInWithEmailAndPassword() method. Add a console.log() statement before the if statement to detect this.

 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); }) }

A more common approach is to have two buttons in the same login page: "Sign Up" and "Sign In" and attach different handler to each button.

eg call firebase.auth().createUserWithEmailAndPassword in " Sign Up " button handler and call firebase.auth().signInWithEmailAndPassword in " Sign In " button handler.

Having two pages (login and signup) doesn't simplify your UI. You would still need to link these two pages together in case a user has landed on the wrong page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM