Clear firebase persistence after logout
<ol>
<li>Is there any way to clear data stored in <a href="https://firebase.google.com/docs/database/">Firebase Database</a> persistence enabled via <code>setPersistenceEnabled(true)</code>?</li>
<li>Or eventually prevent read access to previously stored users data on the device?</li>
<li>And extra question - is there any way to check if any data is waiting to sync?</li>
</ol>

<p>In my app I want to clear db when user is logging out and he confirm that unsynchronized changes will be removed. This app will be used on tablet by many people, and there'll be many data stored per user, so <strong>I want to clear unnecessary data stored on the device</strong> to:</p>

<ul>
<li>shrink storage usage</li>
<li>prevent unauthorized person from read users data</li>
</ul>

<p><strong>It's a security flaw because any user, regardless of whether is signed in or not, has read access to all previously downloaded data!</strong> Fortunately we haven't write access there.</p>

<p>I tried to clear db on my own, in both offline and online mode, but data still persist on the device:</p>

<pre class="lang-java prettyprint-override"><code>// first clear all data on my own
FirebaseDatabase db = FirebaseDatabase.getInstance();
db.goOffline(); // even when I clear db in online mode data persist on mobile device
db.getReference().setValue(null);

// and then logout
FirebaseAuth.getInstance().signOut();
db.goOnline();
</code></pre>

<p>eg data structure:</p>

<pre><code>{
  "someList": {
    "userId1": {
      "itemId11": {
        "name": "name 11"
      },
      "itemId12": {
        "name": "name 12"
      },
      ...
      "itemId1N": {
        "name": "name 1N"
      }
    }
    "userId2": {
      "itemId21": {
        "name": "name 21"
      },
      "itemId22": {
        "name": "name 22"
      },
      ...
      "itemId2N": {
        "name": "name 2N"
      }
    }
  }
}
</code></pre>

<p>my rules:</p>

<pre><code>{
  "rules": {
    ".read": "false",
    ".write": "false",
    "someList": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}
</code></pre>