Can we have Email Id as key in Firebase database? [duplicate]

泄露秘密 提交于 2019-12-30 11:28:30

问题


I want to create a login system , when the user logs in, based on the logged in users email id, I want to retrieve the EID.

The JSON structure I want is:

{
  "joel@dept.com":
       {
            "EID":"0153"
        },
   "Stan@dept.com":
       {
               "EID":"0163"
        }
}

I tried importing the JSON file with above structure into the Firebase projects database, but got an error suggesting "./ ..." cannot be a part of key.


回答1:


i faced the same constraints and i replaced '.' with '__dot__' to make email id as a key.




回答2:


Replacing one character with another may lead to confusion and may cause critical issues in future.

For the instance, replacing . with _DOT_ may work for now. Say in future you want to get back the original email for some verification; [no big deal] I can replace _DOT_ back with .. This fails if someone has the email actual._DOT_@actualdot.com

The solution is to use email hash. I prefer md5 at the moment.

So the structure should be:

{
    "<md5 hash of 'joel@dept.com'>": { 
            "EID":"0153" 
     }, 
    "<md5 hash of 'Stan@dept.com'>": { 
             "EID":"0163" 
    }
 }



回答3:


Firebase does not support characters like .[]{} hence if you want to produce in using the email as the primary key then you will have to replace the .replace(".",",")



来源:https://stackoverflow.com/questions/41713039/can-we-have-email-id-as-key-in-firebase-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!