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