Firebase Auth试图解决诺言时给我一个错误



我需要此Google auth功能的帮助……我在Firebase.js(react)中有一个方法。

doCreateUserWithEmailAndPassword = (email, password) => {
 this.auth
  .createUserWithEmailAndPassword(email, password)
  .then(response => console.log(response))
  .catch(err => console.log(err));};

当我服用然后。

onSubmitHandler = event => {
event.preventDefault();
const { email, passwordOne } = this.state;
this.props.firebase.doCreateUserWithEmailAndPassword(email, passwordOne)
  .then(response => console.log(response))
  .catch(err => console.log(err));
this.props.history.push(ROUTES.HOME);

};

我有这个错误..

TypeError: Cannot read property 'then' of undefined
SignUpFormBase._this.onSubmitHandler
src/components/signUp/signUp.js:31
 28 | onSubmitHandler = event => {
 29 |   event.preventDefault();
 30 |   const { email, passwordOne } = this.state;
 > 31 |   this.props.firebase.doCreateUserWithEmailAndPassword(email, 
 passwordOne)
 | ^  32 |     .then(response => console.log(response))
 33 |     .catch(err => console.log(err));
 34 |   this.props.history.push(ROUTES.HOME);
 View compiled

是的,当我收到错误时,我将其从docreateuserwithemailandpassword中删除。但是该函数确实成功地在Firebase中注册了用户,如果我取出。然后。

为什么我会遇到此错误?

您没有从doCreateUserWithEmailAndPassword返回任何内容,因此它返回undefined并在undefined上调用.then()导致您看到的错误。

只需从doCreateUserWithEmailAndPassword返回Promise即可修复:

doCreateUserWithEmailAndPassword = (email, password) => {
  return this.auth
    .createUserWithEmailAndPassword(email, password)
    .then(response => console.log(response))
    .catch(err => console.log(err));
};

相关内容

最新更新