Firebase Database won't allow a substring of user email

Firebase Database won't allow a substring of user email



I'm trying to write rules in firebase for an app I am making. The way I have my data structured for my users is like this


users
-username (a substring of the users email)
-all other data



where the username is a substring from the text before the period in an email address (for example, johnsmith@gmail.com's username would be johnsmith@gmail). I am trying to write some rules based around this format, but I keep getting this error



Error saving rules - Line 8: Key names can't contain ".", "#", "$", "/", "[", or "]" (unbound names start with "$")


Error saving rules - Line 8: Key names can't contain ".", "#", "$", "/", "[", or "]" (unbound names start with "$")



This is the JSON code I am attempting to use for this rule



"rules":
".read":"auth.uid != null",
".write":false,
"users":
"$substringBefore(auth.token.email,' ')":
".write": true






Can someone explain how I can get it to accept the users email substring for the username node?






Since email addresses can contain ".", "#", "$", "/", "[", and/or "]", I'm wondering how you intend this to work. (Of those, "." is really common, your example user can also get email as "john.smith@gmail.com" without changing anything on his part, gmail silently ignores the dots in the localpart.)

– Cupcake Protocol
Sep 13 '18 at 18:40







@CupcakeProtocol I didn't think about it like that and now I see major flaws in that system. What would be a better way to organize the users?

– stor314
Sep 13 '18 at 18:43






I'm all for letting users pick their own usernames. But that has it's own complexity.

– Cupcake Protocol
Sep 13 '18 at 18:54






Why are you not using their Firebase Auth uid as the key here? This pattern is very well documented and easy to implement. firebase.google.com/docs/database/security/user-security

– Doug Stevenson
Sep 13 '18 at 19:23







@DougStevenson I created the database schema when I didn't know about the uid because I was new to firebase, I was trying to avoid having to restructure my code but it seems as if I'll have to do that in order to allow sufficient security rules.

– stor314
Sep 14 '18 at 15:20




0



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế