auth.uid not a string?

81 views
Skip to first unread message

Ab Scond

unread,
Feb 3, 2015, 9:28:01 PM2/3/15
to fireba...@googlegroups.com
I've whittled this down to the simplest example I can.

1] I have enabled Email & Password Authentication.  There is a user in there with a user ID of 2, which means the user's uid will be 'password:2'.

2] The contents of my Firebase looks like this:

{
  "map" : {
    "password:2" : "bjB2LRQS1"
  }
}

3] My security rules look like this:

{
  "rules": {
    "a": {
      "b": {
        "c": {
          ".write": "newData.exists() && root.child('map').child(auth.uid).val() == newData.child('someKey').val()"
        }
      }
    }
  }
}

4] In the simulator, I do the following:
  • Custom auth: {id: 2, provider: 'password', uid: 'password:2'}
  • Simulate write
  • URL field is:  /a/b/c
  • JSON data is:  {"someKey": "bjB2LRQS1", "time":{".sv":"timestamp"}}
5] That should work, right?  Nope.  Because apparently "auth.uid" isn't a string!  Here's what the simulator says:

Attempt to write {"someKey":"bjB2LRQS1","time":1423016690383} to /a/b/c with auth=null
/
/a
/a/b
/a/b/c:.write: "newData.exists() && root.child('map').child(auth.uid).val() == newData.child('someKey').val()"
6:66: child() expects a string argument.
=> false
No .write rule allowed the operation.
Write was denied.

Any ideas about what am I doing wrong?

Thanks for your help!

- Ab Scond


Jacob Wenger

unread,
Feb 4, 2015, 1:33:36 AM2/4/15
to fireba...@googlegroups.com
Hey there,

Looking at the output from the simulator it says "Attempt to write {"someKey":"bjB2LRQS1","time":1423016690383} to /a/b/c with auth=null". Note that it says auth is null, which is why your rule fails (since auth.uid does not exist). Make sure that click the "Authenticate" button in the simulate to set the auth variable, and then try again. I think it will work for you this time!

Jacob

--
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 post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/edbf0dd2-b1f7-4c72-ae9a-dcc18984441f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ab Scond

unread,
Feb 6, 2015, 2:52:40 AM2/6/15
to fireba...@googlegroups.com
Wait, you mean the giant green button right in the middle of the page that should have been glaringly obvious to me?

Argh, I can't believe I missed that.  I should stop posting questions late at night.  I bet in the morning I would have seen the button.

Kato Richardson

unread,
Feb 6, 2015, 11:23:12 AM2/6/15
to fireba...@googlegroups.com
I've missed it myself a couple of times while working in the simulator. Don't fret too much. It's more frustrating when support has to ask for support.  :)

Reply all
Reply to author
Forward
0 new messages