title: Firestore Security Rules: request.time "undefined on object"
body: <p>I'm trying to create a Security Rule based upon <a href="https://firebase.google.com/docs/reference/rules/rules.firestore.Request#time" rel="noreferrer">request.time</a> as given in an example on <a href="https://angularfirebase.com/lessons/firestore-security-rules-guide/#Time-based-Rules-Examples" rel="noreferrer">AngularFirebase website</a>.</p>
  
  <p>My function is</p>
  
  <pre><code>function isThrottled() {
      return request.time &lt; resource.data.lastUpdate + duration.value(1, 'm')
  }
  </code></pre>
  
  <p>Where I'm trying to <code>allow update: if isThrottled() == false</code></p>
  
  <p>However, when I try to update a document with this rule, it fails due to <strong>time</strong> being not defined on the object.</p>
  
  <blockquote>
    <p>Error: simulator.rules line [169], column [12]. Property time is
    undefined on object.</p>
  </blockquote>
  
  <p>Shouldn't every request have a <code>time</code> or <code>TimeStamp</code> attached to it? Is this something to do with how I'm initializing my Cloud Functions or client app?</p>
  
  <p>Screenshots below:</p>
  
  <p><a href="https://i.stack.imgur.com/yBLjs.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yBLjs.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/RtYOe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/RtYOe.png" alt="enter image description here"></a></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>A snippet for the rest of the update security rules are:</p>
  
  <pre><code>service cloud.firestore {
    match /databases/{db}/documents {
      match /users/{userId} {
        match /username/{id} {
          allow update: if isSelf(userId)
                        &amp;&amp; usernameAvailable(incomingData().username)
                        &amp;&amp; incomingData().username is string
                        &amp;&amp; incomingData().username.size() &lt;= 25
                        &amp;&amp; incomingFields().size() == 1
                        &amp;&amp; isThrottled() == false;
        }
      }
  
      function incomingData() {
        return request.resource.data
      }
      function isThrottled() {
          return request.time &lt; resource.data.lastUpdate + duration.value(1, 'm')
          }
      function incomingFields() {
          return incomingData().keys()
      }
      function isSelf(userId) {
          return userId == currentUser().uid;
      }
      function usernameAvailable(username) {
          return !exists(/databases/$(db)/documents/usernames/$(username));
      }
  
  
    }
  }
  </code></pre>
  
  <p>The <code>username</code> collection is a subcollection under each <code>user</code> document (in the <code>users</code> root collection. Each <code>username</code> document only has 1 field called <code>username</code> that users can update).</p>