【发布时间】:2020-05-07 18:48:09
【问题描述】:
目前我正在开发一种登录模式,它将使用 firebase 功能对用户进行身份验证。如果它们不存在,我计划使用 reactstrap 库将这些框变为红色并发送一条消息,例如“无效的电子邮件或密码”。但是,我是 React 的新手,当我在电子邮件表单中调用 onAuthenticate={firebase.authenticateUser} 时,我在从 firebase 函数获取返回对象/数字时遇到了很多麻烦。如何获取返回对象(如果用户不存在,则为 -1),检查它,如果用户不存在,则关闭模式或使用 react strap 将其变为红色?
我的 firebase 函数的片段,后面是我的 React 模态。
'''
exports.authenticateUser = async (email, password) => {
firebase.auth().signInWithEmailAndPassword(email, password)
.then(() => {
const success = {
success: true,
};
alert('User exists.');
console.log('user exists');
return success;
})
.catch((error) => {
alert('Invalid email or password.');
console.log('no user');
return -1;
});
};
return (
<Modal
title="Please enter log-in information"
onClose={onClose}
footer={modalFooter}
titleBackgroundColor="#FFFACD"
>
<FormGroup>
<Label for="examplePassword">Invalid input</Label>
<Input invalid />
<FormFeedback tooltip>Oh noes! that name is already taken</FormFeedback>
<FormText>Example help text that remains unchanged.</FormText>
</FormGroup>
<EmailForm
onAuthenticate={firebase.authenticateUser}
const returnObj = {firebase.authenticateUser}
/>
</Modal>
);
'''
【问题讨论】:
-
在发布此问题之前,您是否尝试过查看文档或类似问题?
标签: reactjs firebase reactstrap