search regular expression with variable auth.token.email ? (RealTime database)

253 views
Skip to first unread message

laurent nguyen

unread,
May 21, 2020, 10:06:18 AM5/21/20
to Firebase Google Group
Hi,
we tried to make this Realtime database rule work without success.

This is to validate the content of a Post received (sent by a Google sign-in user, we are Gsuite customer and have a domain in .org)

The Post content (newData.val()) must contains the full email, or order to record the Post in the database


With this code, it seems the regular expression is search for an occurrence of the string "auth.token.email"
{
  "rules"
  {   
    "Posts":
    { 
      ".validate" : "newData.val().matches(/auth.token.email/)" 
    }  
  }
}

How to correct it, so that it searches for the content of auth.token.email (email of the signed-in user) ?



thanks a lot in advance,
I could not see in the official documentation so far.

Regards


Kato Richardson

unread,
May 21, 2020, 11:38:17 AM5/21/20
to Firebase Google Group
Laurent,

You're searching for equality, not a contains here. So just newData.val() === auth.token.email.  Also note that auth.token.email may not always be set depending on the provider, authentication state, and user settings. So there are a lot of moving parts that aren't accounted for in your example. See how to ask.

The rules simulator in the console and the emulator on the command line will prove to be much better debuggers than this mailing list. 

At the very least, you should be able to isolate which part of the rule is failing, and an error message, which you can share here so we don't have to do so much guesswork to see what's wrong.

☼, Kato



--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/be7fc691-1813-4e1c-90ef-999196759b0b%40googlegroups.com.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

laurent nguyen

unread,
May 21, 2020, 7:12:54 PM5/21/20
to Firebase Google Group
Hello Kato,
as written in my first post, we solely use Google sign In (IOS firebase) because our users are managed by Gsuite).

An example of Post is: 
-M9nrEuVQmXONztg5LO5  : "Item: diamond \nWhere it was found: here \nEmail: a...@toto.org"

So we can not use an equality

For the simulator, it won't allow to simulate auth.token.email, but we can see that a rule like:
".validate" : "auth.token.email.matches(/.*@toto.org$/)" is working perfectly with Firebase (google sign-in). Thus validating that auth.token.email is well populated by your IOS Firebase SDK (Google Sign in)

That is why we can't report you any simulator error (we won't use the emulator at this step as the development is finishing tomorrow)

2020-05-21_15-15-20.png

Hope it is clarifying the context of that technical question


I tried this rule with Firebase Realtime (not the simulator):
".validate" : "newData.val().contains(auth.token.email)" 

but it still return False

If there is no way to search for a...@toto.org within the Post with Realtime, it is fine in the end,
because our app actually does not need this extended check of security

thanks in advance


On Thursday, May 21, 2020 at 8:38:17 AM UTC-7, Kato Richardson wrote:
Laurent,

You're searching for equality, not a contains here. So just newData.val() === auth.token.email.  Also note that auth.token.email may not always be set depending on the provider, authentication state, and user settings. So there are a lot of moving parts that aren't accounted for in your example. See how to ask.

The rules simulator in the console and the emulator on the command line will prove to be much better debuggers than this mailing list. 

At the very least, you should be able to isolate which part of the rule is failing, and an error message, which you can share here so we don't have to do so much guesswork to see what's wrong.

☼, Kato



On Thu, May 21, 2020 at 7:06 AM laurent nguyen <laure...@gmail.com> wrote:
Hi,
we tried to make this Realtime database rule work without success.

This is to validate the content of a Post received (sent by a Google sign-in user, we are Gsuite customer and have a domain in .org)

The Post content (newData.val()) must contains the full email, or order to record the Post in the database


With this code, it seems the regular expression is search for an occurrence of the string "auth.token.email"
{
  "rules"
  {   
    "Posts":
    { 
      ".validate" : "newData.val().matches(/auth.token.email/)" 
    }  
  }
}

How to correct it, so that it searches for the content of auth.token.email (email of the signed-in user) ?



thanks a lot in advance,
I could not see in the official documentation so far.

Regards


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fireba...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages