Functions Extracting complex logic into reusable functions

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.
Get Unlimited PRO Access


*Enrollment provides full access to this course (and updates) for life.

file_type_firebase firestore.rules
    match /users/{userId} {

      allow read: if isLoggedIn();
      allow write: if belongsTo(userId);


    match /todos/{docId} {

      allow read: if == 'published';

      allow create: if canCreateTodo();

      allow update: if belongsTo() 
                    &&['text', 'status']);

    function isLoggedIn() { 
      return request.auth.uid != null;

    function belongsTo(userId) {    
      return request.auth.uid == userId || request.auth.uid ==;

    function canCreateTodo() {
      let uid = request.auth.uid;
      let hasValidTimestamp = request.time ==;

      return belongsTo(uid) && hasValidTimestamp;


Ask questions via GitHub below OR chat on Slack #questions