title: Firebase Database rules when linking accounts
body: <p>I have Android application that stores data either using anonymous sign in or using logged account. </p>
  
  <p>Problem is when user wants to convert data created as anonymous user into logged account. I linked both anonymous and signed in account with success but I'm getting </p>
  
  <pre><code>SyncTree: Listen at /currentSession/xxx-AnonymousLoginUserId-xx failed: DatabaseError: This client does not have permission to perform this operation
  </code></pre>
  
  <p>I suspect that it is because of access rules but I have no idea how to specify them to tell Firebase that it should accept both accounts.</p>
  
  <p>Rules look like</p>
  
  <pre><code>{
    "rules": {
      "currentSession": {
        "$uid": {
          ".write": "$uid === auth.uid || auth.provider === 'anonymous'",
          ".read": "$uid === auth.uid || auth.provider === 'anonymous'"
        }
      ...
  },
  </code></pre>
  
  <p>Now when I'm thinking about the issue I'm sure that <code>|| auth.provider='anonymous'</code> is wrong but I'm sharing to help you with diagnosis.</p>
  
  <p>BTW: Everything works well in case rules are</p>
  
  <pre><code> {
      "rules": {
        "currentSession": {
          "$uid": {
             ".write": true,
              ".read": true
            }
          ...
   },
  </code></pre>
  
  <p>but I'm not happy with so weak rules</p>
  
  <p>EDIT 1: Syntax error with auth.provider='anonymous' is probably not the cause (I didn't copy it, I just typed it from my memory).</p>
  
  <p>EDIT 2: Please note <code>currentSession : { "$uid" : {</code> ... I realized that most likely the problem is that <code>auth.uid</code> is only one variable but in case of linked accounts it should be probably set of uids. Any idea?</p>