0
0
Firebasecloud~10 mins

Rule syntax and structure in Firebase - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to allow read access to all users.

Firebase
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if [1];
    }
  }
}
Drag options to blanks, or click blank then click option'
Arequest.auth != null
Bfalse
Ctrue
Drequest.time < timestamp.date(2020, 1, 1)
Attempts:
3 left
💡 Hint
Common Mistakes
Using false blocks all access.
Using request.auth != null restricts to signed-in users only.
2fill in blank
medium

Complete the code to allow write access only if the user is authenticated.

Firebase
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow write: if [1];
    }
  }
}
Drag options to blanks, or click blank then click option'
Atrue
Brequest.time > timestamp.date(2023, 1, 1)
Cfalse
Drequest.auth != null
Attempts:
3 left
💡 Hint
Common Mistakes
Using true allows anyone to write.
Using false blocks all writes.
3fill in blank
hard

Fix the error in the rule condition to allow read only if the user is authenticated.

Firebase
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read: if [1];
    }
  }
}
Drag options to blanks, or click blank then click option'
Arequest.auth = null
Brequest.auth != null
Crequest.auth == null
Drequest.auth = true
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment = instead of comparison == or !=.
Checking for null with wrong operator.
4fill in blank
hard

Fill both blanks to allow write access only if the user is authenticated and the document ID matches the user ID.

Firebase
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/[1] {
      allow write: if request.auth != null && request.auth.uid == [2];
    }
  }
}
Drag options to blanks, or click blank then click option'
A{userId}
Brequest.auth.uid
CuserId
Ddocument.id
Attempts:
3 left
💡 Hint
Common Mistakes
Using userId without braces in the path.
Using request.auth.uid instead of userId.
5fill in blank
hard

Fill all three blanks to allow read access only to authenticated users and only for documents in the 'posts' collection where the post is published.

Firebase
service cloud.firestore {
  match /databases/{database}/documents {
    match /posts/[1] {
      allow read: if request.auth != null && resource.data.[2] == [3];
    }
  }
}
Drag options to blanks, or click blank then click option'
A{postId}
Bpublished
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using false instead of true for published check.
Not capturing the document ID in the path.