我正在构建一个注册页面,该页面会将数据保存在API中,但它会不断返回error 400 bad request
,即使我正确发送了所有数据,它也表示需要输入电子邮件和密码。我检查了一下,并根据表格中键入的内容正确发送了电子邮件和密码。
const [manager, setManager] = useState({
company: "" ,
email: "",
password: "",
accessLevel:1
})
console.log(manager)
const handleSubmit = () => {
axios.post(`https://reembolsa-ai-api.herokuapp.com/register`, {manager})
.then(res => console.log(res.data))
.catch(error => console.log(error))
}
const onFinishFailed = (errorInfo) => {
console.log('Failed:', errorInfo);
};
const [form] = Form.useForm();
const onFinish = () => {
handleSubmit();
form.resetFields();
};
return (
<Container>
<Titulo>Cadastro</Titulo>
<StyledForm
{...layout}
form={form}
name="basic"
initialValues={{
remember: true,
}}
onFinish={onFinish}
onFinishFailed={onFinishFailed}
>
<StyledLabel>Empresa</StyledLabel>
<Form.Item
name="company"
rules={[
{
required: true,
message: 'Digite o nome da sua empresa',
},
]}
>
<StyledInput onChange={({target: {value}}) =>
setManager({...manager, company: value})} placeholder="Insira o nome da sua empresa" value={manager.company}/>
</Form.Item>
<StyledLabel>E-mail</StyledLabel>
<Form.Item
name="email"
rules={[
{
required: true,
message: 'Digite um e-mail válido',
},
]}
>
<StyledInput onChange={({target: {value}}) =>
setManager({...manager, email: value})} placeholder="Insira seu e-mail" value={manager.email} />
</Form.Item>
<StyledLabel>Senha</StyledLabel>
<Form.Item
name="password"
rules={[
{
required: true,
message: 'Digite uma senha',
},
]}
>
<StyledInputPassword onChange={({target: {value}}) =>
setManager({...manager, password: value})} placeholder="Insira sua senha" value={manager.password}/>
</Form.Item>
<StyledLabel>Confirme sua senha</StyledLabel>
<Form.Item
name="confirmPassword"
rules={[
{
required: true,
message: 'Confirme sua senha',
},
]}
>
<StyledInputPassword placeholder="Confirme sua Senha"/>
</Form.Item>
<ContainerButtons>
<Form.Item {...tailLayout} >
<StyledButtonRed to="/login" >
<BiDownArrow/>
</StyledButtonRed>
</Form.Item>
<Form.Item {...tailLayout} >
<StyledButtonGreen type="primary" htmlType="submit">
<BiUpArrow/>
</StyledButtonGreen>
</Form.Item>
</ContainerButtons>
</StyledForm>
</Container>
);
};
我该如何解决?
答案 0 :(得分:0)
最有可能在后端出现问题。检查您正在传输的数据结构的正确性