简体   繁体   English

Firebase 身份验证为 createUserWithEmailAndPassword 返回未定义

[英]Firebase Auth returning undefined for createUserWithEmailAndPassword

I have a function that creates a new user through Firebase Auth, and for awhile I had it working but now it's returning undefined.我有一个通过 Firebase Auth 创建新用户的函数,有一段时间我让它工作,但现在它返回未定义。 I tried using async await to wait for an input with no help, and I'm not really sure what could be going wrong.我尝试在没有帮助的情况下使用 async await 等待输入,但我不确定会出现什么问题。 I can't include my Firebase auth code on here, but I put the rest of the code on CodePen:我不能在此处包含我的 Firebase 身份验证代码,但我将其余代码放在 CodePen 上:

https://codepen.io/TheNomadicAspie/pen/ZEKYwWJ https://codepen.io/TheNomadicAspie/pen/ZEKYwWJ

And here are the relevant function:这是相关的功能:

function newUserSubmitEmail() {
    traceFunction()
    new_user_dict['email'] = input_text.value.trim()
    console.log('newUserSubmitEmail email is ', new_user_dict['email'])
    question.innerText = "What password would you like to use?"
    input_text.value = ''
    right_button.onclick = newUserSubmitPassword
}

function newUserSubmitPassword() {
    traceFunction()
    new_user_dict['password'] = input_text.value.trim()
    console.log('newUserSubmitPassword password is ', new_user_dict['password'])
    question.innerText = "Ok, and enter it one more time just to make sure there's no typos."
    input_text.value = ''
    right_button.onclick = newUserVerifyPassword
}

function newUserVerifyPassword() {
    traceFunction()
    if (new_user_dict['password'] === input_text.value) {
        newUserSubmitEmailAndPassword()
    } else {
        question.innerText = "Those passwords didn't match. Let's try again."
        console.log('newUserVerifyPassword old password was ', new_user_dict['password'], ' new password is ', input_text.value)
        input_text.value = ''
        right_button.onclick = newUserSubmitPassword
    }
}

async function newUserSubmitEmailAndPassword() {
    traceFunction()
    console.log('newUserSubmitEmailAndPassword email is ', new_user_dict['email'], ' password is ', new_user_dict['password'])
    input_text.value = ''
    firebase.auth().createUserWithEmailAndPassword(await new_user_dict['email'], await new_user_dict['password']).then((userCredential) => {
            console.log('newUserSubmitEmailAndPassword User created successfully')
            userCreatedSuccessfully()
        })
        .catch(async (error) => {
            var errorCode = await error.code
            var errorMessage = error.message
            question.innerText = errorCode
            console.log('newUserSubmitEmailAndPassword Error creating user. Error code: ', errorCode, ' ', errorMessage)
            if (errorCode === 'auth/email-already-in-use') {
                newUserEmailInUse()
            } else if (errorCode === 'auth/invalid-email') {
                newUserTryEmailAgain()
            } else if (errorCode === 'auth/operation-not-allowed') {
                errorPleaseRefresh()
            } else if (errorCode === 'auth/weak-password') {
                newUserTryPasswordAgain()
            }
        })
}

Any ideas?有任何想法吗?

Maybe it's because you use the await in the wrong place.也许是因为您在错误的地方使用了await The code is written with async/await like this:代码是用async/await编写的,如下所示:

try {
  const userCredentials = await firebase
    .auth()
    .createUserWithEmailAndPassword(
      new_user_dict["email"],
      new_user_dict["password"]
    );
  console.log(
    "newUserSubmitEmailAndPassword User created successfully",
    userCredentials.user
  );
  // comment out this
  //userCreatedSuccessfully();
} catch (error) {
  var errorCode = await error.code;
  var errorMessage = error.message;
  question.innerText = errorCode;
  console.log(
    "newUserSubmitEmailAndPassword Error creating user. Error code: ",
    errorCode,
    " ",
    errorMessage
  );
  if (errorCode === "auth/email-already-in-use") {
    newUserEmailInUse();
  } else if (errorCode === "auth/invalid-email") {
    newUserTryEmailAgain();
  } else if (errorCode === "auth/operation-not-allowed") {
    errorPleaseRefresh();
  } else if (errorCode === "auth/weak-password") {
    newUserTryPasswordAgain();
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 firebase.auth().createUserWithEmailAndPassword Undefined 不是函数 - firebase.auth().createUserWithEmailAndPassword Undefined is not a function Firebase 在 React 应用程序中验证 createUserWithEmailAndPassword - Firebase Auth createUserWithEmailAndPassword in React app firebase.auth()。createUserWithEmailAndPassword()如何工作? - How does firebase.auth().createUserWithEmailAndPassword() works? 将文档添加到 firebase auth.createUserWithEmailAndPassword 内的集合中 - Adding document to a collection within .then of firebase auth.createUserWithEmailAndPassword Firebase身份验证-createUserWithEmailAndPassword()-在验证电子邮件之前禁止登录 - Firebase Auth - createUserWithEmailAndPassword() - prevent login until email is verified firebase__webpack_imported_module_2__.auth.createuserwithemailandpassword 不是函数。? - firebase__webpack_imported_module_2__.auth.createuserwithemailandpassword is not a function.? Firebase 错误 auth/admin-restricted-operation 在 createUserWithEmailAndPassword 之后 - Firebase Error auth/admin-restricted-operation after createUserWithEmailAndPassword 尝试呈现 Firebase 身份验证详细信息在 React web 应用程序中返回“未定义” - Attempting to render Firebase Auth details returning 'undefined' in React web app auth.createUserWithEmailAndPassword 不是函数 - auth.createUserWithEmailAndPassword is not a function Firebase createUserWithEmailAndPassword上的超时连接 - Timeout connection on firebase createUserWithEmailAndPassword
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM