0
0
Firebasecloud~10 mins

Common rule patterns 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 only to authenticated users.

Firebase
allow read: if request.auth [1] null;
Drag options to blanks, or click blank then click option'
A<
B==
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' causes the rule to allow only unauthenticated users.
Using comparison operators like '<' or '>' is invalid here.
2fill in blank
medium

Complete the code to allow write access only if the user's UID matches the document ID.

Firebase
allow write: if request.auth.uid [1] resource.id;
Drag options to blanks, or click blank then click option'
A==
B!=
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' allows users to write to documents not matching their UID.
Using '<=' or '>' is not meaningful for string comparison here.
3fill in blank
hard

Fix the error in the rule that allows read access only if the user is authenticated and the document is public.

Firebase
allow read: if request.auth [1] null && resource.data.public == true;
Drag options to blanks, or click blank then click option'
A===
B!=
C==
D!==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' allows unauthenticated users to read.
Using strict equality operators like '===' is not supported in Firebase rules.
4fill in blank
hard

Fill both blanks to allow update only if the user is authenticated and the new data has a 'status' field equal to 'active'.

Firebase
allow update: if request.auth [1] null && request.resource.data.status [2] 'active';
Drag options to blanks, or click blank then click option'
A!=
B==
C===
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' for authentication check allows unauthenticated users.
Using '===' causes syntax errors in Firebase rules.
5fill in blank
hard

Fill all three blanks to allow delete only if the user is authenticated, the document owner matches the user, and the document is not locked.

Firebase
allow delete: if request.auth.uid [1] resource.data.owner && request.auth [2] null && resource.data.locked [3] false;
Drag options to blanks, or click blank then click option'
A==
B!=
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up operators causes the rule to allow unauthorized deletes.
Checking locked with '!=' false would allow locked documents to be deleted.