简体   繁体   English

尝试解决承诺时,Firebase Auth给我一个错误

[英]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.

相关问题 链接两个Firebase身份验证方法给我错误-javascript - Linking two firebase auth methods giving me error - javascript 承诺拒绝给我一个UnhandledPromiseRejectionWarning错误 - Promise reject giving me an UnhandledPromiseRejectionWarning error 尝试在客户端使用 Firebase 身份验证服务注册用户时出错。 Firebase:错误(auth.network-request-failed) - Error when trying to register a user using Firebase Auth service on the client side. Firebase: Error (auth/network-request-failed) Firebase 解析 Promise - Firebase resolve Promise 为什么在答应给我一个错误后在ExpressJS中使用then()回调? - Why does using then() callback in ExpressJS after a promise giving me an Error? 试图做出承诺的决心 - trying to do a resolve with a promise 尝试在动态渲染操作中调用数据时,数组 map 给我一个错误 - Array map is giving me an error when trying to call the data in a dynamic render operation 尝试在 firebase 中链接多个身份验证提供程序时,从 error.email 中获取“未定义” - Getting "undefined" from error.email when trying to link multiple auth providers in firebase 为什么 Firebase email 验证给我一个 http 400 错误? - Why is Firebase email verification giving me a http 400 error? 在这里,我尝试使用 firebase 身份验证登录,但出现 400 错误。 我给出了准确的 email 和密码,但它显示如下错误 - Here, I am trying to login using firebase auth, but getting 400 error. I am giving exact email & password but it's showing below error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM