Reactjs 反应:POST 500(内部服务器错误)axios.POST

Reactjs 反应:POST 500(内部服务器错误)axios.POST,reactjs,axios,google-cloud-functions,Reactjs,Axios,Google Cloud Functions,我目前正在做一个个人项目,我现在被登录页面卡住了。我提到我使用Firebase云函数和axios来发布/获取请求 因此,这是用于登录的云函数: app.post('/login', (req,res) => { const user = { email: req.body.email, password: req.body.password, }; let errors = {}; if(isEmpty(user.emai

我目前正在做一个个人项目,我现在被登录页面卡住了。我提到我使用Firebase云函数和axios来发布/获取请求

因此,这是用于登录的云函数:

app.post('/login', (req,res) => {
    const user = {
        email: req.body.email,
        password: req.body.password,
    };

    let errors = {};

    if(isEmpty(user.email)) errors.email = 'Must not be empty !';
    if(isEmpty(user.password)) errors.email = 'Must not be empty !';
    
    if(Object.keys(errors).length > 0) return res.status(400).json(errors);

    firebase.auth().signInWithEmailAndPassword(user.email,user.password)
            .then(() => {
                return res.json(user.email);
            })
            .catch(err => {
                console.error(err);
                res.status(500).json({error: err.code});
            })

})
这很好,因为我可以通过邮递员发送数据

下面是Login.js中的代码:

    const [email,setEmail] = useState("");
    const [password,setPassword] = useState("");

    const handleSubmit = (e) => {
        e.preventDefault();
        axios
            .post('/login', {
                email: email,
                password: password,
            })
            .then((res) => {
                console.log(res.data);
                this.props.history.push('/');
            })
            .catch((err) => {
                console.log(err);
            })
    }
以下是表格:

<input value={email} onChange={(e) => setEmail(e.target.value)} id="email" name="password" className="login__input" type="email" placeholder="Email"/>

<input value={password} onChange={(e) => setPassword(e.target.value)} id="password" name="password" className="login__input" type="password" placeholder="Password"/>

<button onClick={handleSubmit} className="login__button" type="submit">Connect</button
在这种状态下,我得到一个500内部服务器错误状态。 我尝试了许多不同的选项,这些选项给了我访问控制允许原点错误,尽管我试图修复它,但似乎两种方式都不起作用

编辑:

控制台:

> functions: Beginning execution of "api"
> >  [t [Error]: The email address is badly formatted.] {
> >    code: 'auth/invalid-email',
> >    a: null
> >  } i  functions: Finished "api" in ~1s i  functions: Beginning execution of "api" i  functions: Finished "api" in ~1s i  functions:
> Beginning execution of "api"
> >  [t [Error]: The password is invalid or the user does not have a password.] {
> >    code: 'auth/wrong-password',
> >    a: null
> >  } i  functions: Finished "api" in ~1s i  functions: Beginning execution of "api"
> >  [t [Error]: The password is invalid or the user does not have a password.] {
> >    code: 'auth/wrong-password',
> >    a: null
> >  } i  functions: Finished "api" in ~1s i  functions: Beginning execution of "api"
> >  [t [Error]: The password is invalid or the user does not have a password.] {
> >    code: 'auth/wrong-password',
> >    a: null
> >  } i  functions: Finished "api" in ~1s i  functions: Beginning execution of "api" i  functions: Finished "api" in ~1s

谢谢。

您的云功能代码中有一个错误。请编辑问题以显示您在控制台日志中看到的内容。Done it@DougStevenson这不是您的云功能控制台日志。这是您的web浏览器控制台日志。@DougStevenson我更新了它,我尝试了不同的输入,它似乎工作了??但它并没有把我引向头版,我已经弄明白了。关于this.props.history.push也有一个错误,但由于这个答案,我解决了它:(以防有人得到和我一样的“bug”)。无论如何,谢谢。您的云函数代码中有一个错误。请编辑问题以显示您在控制台日志中看到的内容。Done it@DougStevenson这不是您的云功能控制台日志。这是您的web浏览器控制台日志。@DougStevenson我更新了它,我尝试了不同的输入,它似乎工作了??但它并没有把我引向头版,我已经弄明白了。关于this.props.history.push也有一个错误,但由于这个答案,我解决了它:(以防有人得到和我一样的“bug”)。无论如何谢谢你。
> functions: Beginning execution of "api"
> >  [t [Error]: The email address is badly formatted.] {
> >    code: 'auth/invalid-email',
> >    a: null
> >  } i  functions: Finished "api" in ~1s i  functions: Beginning execution of "api" i  functions: Finished "api" in ~1s i  functions:
> Beginning execution of "api"
> >  [t [Error]: The password is invalid or the user does not have a password.] {
> >    code: 'auth/wrong-password',
> >    a: null
> >  } i  functions: Finished "api" in ~1s i  functions: Beginning execution of "api"
> >  [t [Error]: The password is invalid or the user does not have a password.] {
> >    code: 'auth/wrong-password',
> >    a: null
> >  } i  functions: Finished "api" in ~1s i  functions: Beginning execution of "api"
> >  [t [Error]: The password is invalid or the user does not have a password.] {
> >    code: 'auth/wrong-password',
> >    a: null
> >  } i  functions: Finished "api" in ~1s i  functions: Beginning execution of "api" i  functions: Finished "api" in ~1s