在Firebase用户表中添加额外的详细信息 [英] Add Extra Details on Firebase User Table

查看:103
本文介绍了在Firebase用户表中添加额外的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个firebase + angularjs应用程序,我正在使用简单的电子邮件和密码身份验证,它正常工作。



我只是想我可以在firebase email + password auth使用的用户表上添加额外的用户数据,例如我想添加有关用户的帐单信息和其他详细信息,而无需在firebase上创建额外的节点/表来存储这些额外的数据。 由于许多应用程序开发人员想要在其应用程序代码中访问用户数据,所以通常将所有用户存储在应用程序数据库本身内的 / users 节点。缺点是你必须自己做这个。但是,积极的一面是,你可以存储任何额外的信息,如果你想要。



请参阅示例代码存储用户数据的Firebase指南。从那里:

  var ref = new Firebase(https://< YOUR-FIREBASE-APP> .firebaseio.com ); 
ref.onAuth(function(authData){
if(authData&& isNewUser){
//将用户个人资料保存到Firebase中,以便我们列出用户
/ /在安全和Firebase规则中使用它们,并显示配置文件
ref.child(users)。child(authData.uid).set({
provider:authData.provider,
name :getName(authData)
});
}
});


I'm working on a firebase+angularjs app and I'm using the simple email and password authentication and it's working properly.

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 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.

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.

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用户表中添加额外的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆