问题描述
我正在开发一个 firebase+angularjs 应用程序,我正在使用简单的电子邮件和密码身份验证,它运行正常.
I'm working on a firebase+angularjs app and I'm using the simple email and password authentication and it's working properly.
我只是想知道是否可以在 firebase email+password auth 使用的用户表上添加额外的用户数据,就像我想添加帐单信息和其他有关用户的详细信息而无需在上创建额外的节点/表firebase 来存储这些额外的数据.
I'm just wondering if I can add extra user data on the user table which is being used by firebase email+password auth, like I want to add billing info and other details concerning the user without creating extra node/table on firebase to store these extra data.
推荐答案
Firebase 将电子邮件/密码用户存储在您无法直接访问的单独位置.您无法扩展此位置的数据.
Firebase stores the email/password users in a separate location, that you don't have direct access to. You cannot expand the data in this location.
由于许多应用程序开发人员希望访问其应用程序代码中的用户数据,因此将所有用户存储在应用程序数据库本身内的 /users
节点下是一种常见做法.缺点是你必须自己做这件事.但这样做的好处是,您可以根据需要存储任何额外信息.
Since many application developers want to access the user data in their application code, it is a common practice to store all users under a /users
node inside the application database itself. The disadvantage is that you have to do this yourself. But the positive side of this is that you can store any extra information if you want.
请参阅 有关存储用户数据的 Firebase 指南 示例代码.从那里:
See the Firebase guide on storing user data for sample code. From there:
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.onAuth(function(authData) {
if (authData && isNewUser) {
// save the user's profile into Firebase so we can list users,
// use them in Security and Firebase Rules, and show profiles
ref.child("users").child(authData.uid).set({
provider: authData.provider,
name: getName(authData)
});
}
});
这篇关于在 Firebase 用户表上添加额外的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!