我需要此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));
};