0
0
Firebasecloud~10 mins

Data validation rules 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 if the user is authenticated.

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 access only for 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 ID 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 data that is not theirs.
Using '<=' or '>=' is not meaningful for string IDs.
3fill in blank
hard

Fix the error in the rule to allow writes only if the new data has a 'score' field that is a number.

Firebase
allow write: if request.resource.data.score [1] int;
Drag options to blanks, or click blank then click option'
Ais
Bin
Ctypeof
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' compares the value to the string 'number', which is incorrect.
Using 'typeof' is not valid syntax in Firebase rules.
4fill in blank
hard

Fill both blanks to allow writes only if the new data has a 'name' field that is a string and is not empty.

Firebase
allow write: if request.resource.data.name [1] string && request.resource.data.name.[2] > 0;
Drag options to blanks, or click blank then click option'
Ais
Blength
Csize
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'is' for type checking.
Using 'length' or 'count' which are not valid string properties in Firebase rules.
5fill in blank
hard

Fill all three blanks to allow writes only if the user is authenticated, the 'age' field is a number, and the age is at least 18.

Firebase
allow write: if request.auth [1] null && request.resource.data.age [2] int && request.resource.data.age [3] 18;
Drag options to blanks, or click blank then click option'
A!=
Bis
C>=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' for authentication check.
Using '<' instead of '>=' for age comparison.