实时引用身份验证数据库数据库firebase [英] Referencing authentication db data in real time db firebase

查看:161
本文介绍了实时引用身份验证数据库数据库firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用firebase建立一个登录和注册设施的网站。我已经使用firebase的身份验证数据库来存储注册的用户。但是,身份验证数据库不会存储除emailid,密码和自动生成的UUID之外的任何内容。



I需要为用户存储更多的数据,如用户名,个人资料图片等。我会使用firebase的实时数据库相同。



我的问题是做同样的最佳做法是什么。我应该使用UID作为身份验证数据库中的主键,并将其保存为实时数据库中的外键,如下所示: b
$ b

 记录1  - 电子邮件:abc@test.com;密码:somepassword; UID:UID1 
记录2 - 电子邮件:abcd@test.com;密码:somepassword; UID:UID2

实时数据库结构:

 用户
|
| --UID1
|
| ---名称:Amanda
| ---姓:Waller
| ---年龄:30
| --UID2
|
| ---名字:MyName
| ---姓氏:名字
| ---年龄:39

或者使用电子邮件ID作为主键而不是使用Firebase的自动生成的UID更好。因为在sql中我们通常不使用自动生成的id作为主键。

解决方案

最好使用UID。一方面,你不能在键上有句点,所以如果你使用电子邮件作为键,你必须通过用其他字符替换它来处理。此外,某些形式的身份验证不需要电子邮件,如Twitter。既然你可以很容易地得到UID,一旦用户通过身份验证,这就是我推荐的。


I am making a website with login and registration facility using firebase. I have used firebase "Authentication" database to store the registered users.However, "Authentication" database doesnt store anything other then emailid, password and an auto generated UUID.

I need to store more data like username, profile pic etc for a user. I would be using firebase's "real time" database for the same.

My question is what is the best practise to do the same. Should I use the UID as primary key from "authentication" database and keep it as foreign key in my real time database like below:

Authentication db:

Record 1 - Email:abc@test.com; password:somepassword; UID:UID1
Record 2 - Email:abcd@test.com; password:somepassword; UID:UID2

RealTime db structure:

users
|
|--UID1
   |
   |---Name:Amanda
   |---Surname:Waller
   |---age:30
|--UID2
   |
   |---Name:MyName
   |---Surname:Mysurname
   |---age:39

Or is it better to use email id as primary key instead of using firebase's auto-generated UID. Because in sql we do not generally use the autogenerated ids as primary keys.

解决方案

It’s better to use the UID. For one thing, you can’t have periods in keys, so if you use email as a key you’ll have to handle that by replacing them with some other character. Also, some forms of authentication don’t require email, like Twitter. Since you can get the UID easily once the user is authenticated, that’s what I’d recommend.

这篇关于实时引用身份验证数据库数据库firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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