[英]Firebase Auth Is Giving Me An Error When Trying To Resolve A Promise
I need help with this Google Auth Function… I have a method doCreateUserWithEmail and password in firebase.js (React) that looks like this. 我需要有关此Google身份验证功能的帮助…我在firebase.js(反应)中有一个doCreateUserWithEmail方法和密码,如下所示。
doCreateUserWithEmailAndPassword = (email, password) => {
this.auth
.createUserWithEmailAndPassword(email, password)
.then(response => console.log(response))
.catch(err => console.log(err));};
When I take then .then and below and and attach it to signUp.js like so… 当我接.then及以下内容并将其附加到signUp.js时,就像这样……
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);
}; };
I get this error.. 我收到此错误。
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
and yes, I deleted it off of doCreateUserWithEmailAndPassword when I get the error.. but the function does register the user in Firebase successfully, and if I take away the .then and .catch it works fine. 是的,当我收到错误消息时,我将其从doCreateUserWithEmailAndPassword中删除了。.但是该函数确实在Firebase中成功注册了用户,并且如果我拿走.then和.catch,它就可以正常工作。
Why do I get this error? 为什么会出现此错误?
You aren't returning anything from doCreateUserWithEmailAndPassword
so it returns undefined
and calling .then()
on undefined
causes the error you are seeing. 您没有从doCreateUserWithEmailAndPassword
返回任何内容,因此它返回undefined
并且对undefined
调用.then()
会导致您看到的错误。
Just return the Promise
from doCreateUserWithEmailAndPassword
and that should fix it: 只需从doCreateUserWithEmailAndPassword
返回Promise
解决该问题:
doCreateUserWithEmailAndPassword = (email, password) => {
return this.auth
.createUserWithEmailAndPassword(email, password)
.then(response => console.log(response))
.catch(err => console.log(err));
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.