【发布时间】:2018-07-20 09:27:34
【问题描述】:
我已手动为以下用户导入数据库的 JSON 文件:
{
"users": {
"Naseebullah": {
"name": "Naseebullah Ahmadi",
"gender": "Male",
"type": "Patient",
"Doctors": ["Ernest"],
"age": "20",
"DOB": "02/06/1997",
"address": "122 Atherstone Court",
"contactNumber": "07473693312",
"emailAddress": "Naseebullah@kcl.ac.uk",
"profilePicture": "../Images/profile.jpg",
"ECG": [0, 0, 0, 0, 0.0000050048828125, 0.0000137939453125],
"HeartSound": [0, 0, 0, 0, 0.0000050048828125, 0.0000137939453125]
},
"Ernest": {
"name": "Ernest Kamavuako",
"gender": "Male",
"type": "Doctor",
"Patients": ["Naseebullah"],
"age": "30",
"DOB": "20/12/1970",
"address": "122 Harrow Street",
"contactNumber": "07473033312",
"emailAddress": "Ernest@kcl.ac.uk",
"profilePicture": "../Images/profile.jpg",
"ECG": [""],
"HeartSound": [""]
}
}
}
问题是当我以“Naseebullah”(naseebullah@kcl.ac.uk) 身份登录时,我没有收到他的详细信息:
"Naseebullah": {
"name": "Naseebullah Ahmadi",
"gender": "Male",
"type": "Patient",
"Doctors": ["Ernest"],
"age": "20",
"DOB": "02/06/1997",
"address": "122 Atherstone Court",
"contactNumber": "07473693312",
"emailAddress": "Naseebullah@kcl.ac.uk",
"profilePicture": "../Images/profile.jpg",
"ECG": [0, 0, 0, 0, 0.0000050048828125, 0.0000137939453125],
"HeartSound": [0, 0, 0, 0, 0.0000050048828125, 0.0000137939453125]
},
也就是说,我不知道他的名字、性别等等……
这是我验证的地方:
const onLogin = creds => {
const { email, password } = creds;
//console.log("props123 ", values, nav);
firebase.auth().signInWithEmailAndPassword(email, password).then((user) => {
console.log("user: ", user);
/*
* User is logged in
*
* */
}).catch(err => {
const { code,message } = err;
console.log("not loggedin, ", message);
});
};
当用户通过电子邮件和密码进行身份验证后,如何从数据库中检索用户的详细信息?
【问题讨论】:
-
看起来
email在您的身份验证和数据库中很常见。所以首先从 auth 获取邮件,然后查询拥有特定邮件的用户并显示数据。 -
您是否暗示我们将电子邮件作为对个人进行分类的唯一键?我认为这是不安全的,不是吗? @Hareesh
-
有没有更好的替代方法?
-
这是我认为您现在可以联系到当前用户的唯一方法。
标签: javascript firebase react-native firebase-realtime-database firebase-authentication