1
votes

I would like to compute hash functions inside security rules.

md5hash(auth.token.email) === $hashedvalue

Is there a way for me to do that in bolt? or natively in firebase real-time database?

Use Case:

Basically I would like to store the email as the key in the firebase real-time database and use it in the firebase security rules for authentication and authorization. Since few special characters like dots (.) are not supported in keys I was thinking of using some hashing algorithm which is available in firebase real-time database.

auth.id doesn't work in my case as I'm not giving any sign up option as I have a pre defined set of users with pre-defined profile details accessing my application through their Google login (which I know the email ID of) to start with and since they haven't yet logged into my application I don't have a corresponding ID to authenticate or authorize them on their first attempt.

2

2 Answers

1
votes

This page of documentation shows all the functions available in Realtime Database security rules. There are no hashing functions there. You could file a feature request to explain you use case.

1
votes

For the sake of posterity, I got this working with a small workaround (Yay!).

From the fire firebase real-time database documentation I found out that firebase security rules supports an amazing string function called "replace" xD. So now I pre process the email Ids by replacing all the characters not supported as database key with their url encoding equivalent before creating the key and use the same set of replacements in my firebase security rules.