4
votes

I'm new to using Firebase (I'm using react-redux-firebase, but not sure if that's relevant to this question). I'm having an issue using these standard auth rules:

{
   "rules": {
      "users": {
         "$uid": {
            ".read": "$uid === auth.uid",
            ".write": "$uid === auth.uid"
         }
      }
   }
}

This is user UID as shown in the Firebase Authentication dashboard:

enter image description here

But if I print out the data associated with the profile/account, I get this UID:

enter image description here

Because of this mismatch, the logged in user is unable to read or write to the firebase instance.

enter image description here

Why is there a mismatch in UIDs? How can I solve this issue?

UPDATE:

It looks like the 1091103… UID is provider-specific and not relevant in this case? Can't confirm that for sure.

This may be the actual auth UID (I'm new to this, so still trying to figure out what's what):

enter image description here

In this case, this UID matches what is seen in the Firebase console. If they match, then what would be the cause of the permission denied errors?

ANOTHER UPDATE:

Here's the user node. You can see the UID as the key:

enter image description here

1
i thinks that is Provider-specific UID form google sign in. not auth UID - Hareesh
check under users you have the correct auth UID listed, otherwise you are saving wrong UID to users database - Hareesh
It appears that they match. Looking through the Firebase database there are no mismatches of UIDs. So in that case, I'm not sure why I'm getting permission denied errors. Updated my question to reflect this. - timothym
how is your users collection looks? or provide the code for writing users. - Hareesh
are you using .push to write to users? - Hareesh

1 Answers

0
votes

This is the rule you can do right now

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

if you want to check like below

{
   "rules": {
      "users": {
         "$uid": {
            ".read": "$uid === auth.uid",
            ".write": "$uid === auth.uid"
         }
      }
   }
}

you need to store the users to realtime database while register. with their auth.uid as key.