【问题标题】:I am getting First argument "email" must be a valid string error while firebase authentication in react我得到第一个参数“电子邮件”必须是一个有效的字符串错误,而firebase身份验证反应
【发布时间】:2021-02-08 02:13:50
【问题描述】:

我正在尝试为我的 react 应用程序构建 firebase 身份验证。但是在单击登录按钮后我显示此错误

第一个参数“email”必须是有效字符串。

这是我按下按钮时激活的功能

const login = async (e) => {
        try{
            e.preventDefault();
            console.log(email)
            console.log(typeof email)
            console.log(password)
            await firebaseApp.login()
            history.push('/daily')
        }catch(error){
            alert(error.message)
        }
    }

这就是firebaseApp类的登录功能

login(email, password){
    return this.auth.signInWithEmailAndPassword(email, password)
  }

奇怪的是,当我尝试控制台记录电子邮件类型时,它会显示字符串,还会显示我输入的电子邮件和密码 但它仍然给了我错误。我哪里出错了?

【问题讨论】:

  • 为什么你不在这里传递电子邮件和密码await firebaseApp.login()? (登录方法的参数)
  • 我只是忘了这样做...非常感谢您指出它..它太傻了
  • 没关系,发生了!

标签: javascript reactjs firebase firebase-authentication


【解决方案1】:

你的登录函数有两个参数,邮箱和密码:

login(email, password){
    return this.auth.signInWithEmailAndPassword(email, password)
}

但是你调用它时没有参数:

firebaseApp.login()

这意味着电子邮件和密码将为undefined,这不是有效的字符串值。这就是错误消息告诉您的内容。

传递正确的参数:

firebaseApp.login(email, password)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-23
    • 2021-02-10
    • 2020-09-24
    • 2018-03-04
    • 2018-08-29
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    相关资源
    最近更新 更多