title: Firebase Realtime Database prevent delete - based on condition
body: <p>I would like to prevent deletion of data in Firebase Realtime Database based on a condition. A user that is not author should be able to update the &quot;note&quot;, but not delete it.</p>
  <p>I have a collection of &quot;notes&quot; in my database that has the following rule set.</p>
  <pre><code>&quot;notes&quot;: {
    &quot;.read&quot;: &quot;
      auth.uid !== null //&amp;&amp;
    &quot;,
    &quot;$note_id&quot;: {
      &quot;.write&quot;: &quot;
        //New data
        !data.exists() &amp;&amp; auth.uid !== null ||
        //Existing data
        data.child('access').child('author').val() === auth.uid ||
        data.child('access/members').child(auth.uid).exists()          
      &quot;,
      &quot;data&quot;: { .. },
      &quot;access&quot;: {
        &quot;author&quot; : { .. },
        &quot;members&quot; : { .. }
      }
    }
  }
  </code></pre>
  <p>How can I only allow &quot;author&quot; to delete the &quot;note&quot;?</p>
  <p>I have tried using Google Cloud Functions for Firebase, but only have access to the <code>.onDelete()</code> event which is run <em>after</em> delete is already performed. Could I use the <code>.onWrite()</code> for this purpose - and if so how? I have already implemented listeners for <code>.onCreate()</code> <code>.onUpdate()</code> and <code>.onDelete()</code> for the <strong>/notes</strong> node in the database.</p>