0
0
Firebasecloud~10 mins

Authentication-based 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];
Drag options to blanks, or click blank then click option'
A=== false
B!== true
C== null
D!= null
Attempts:
3 left
💡 Hint
Common Mistakes
Using '== null' which allows unauthenticated users.
Using strict equality with booleans which 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 '!=' which denies access to the owner.
Using comparison operators like '<' or '>' which are invalid here.
3fill in blank
hard

Fix the error in the rule to allow read access only if the user is authenticated and email is verified.

Firebase
allow read: if request.auth [1] request.auth.token.email_verified == true;
Drag options to blanks, or click blank then click option'
A==
B||
C&&
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '||' which allows access if only one condition is true.
Using '==' or '!=' which are comparison operators, not logical.
4fill in blank
hard

Fill both blanks to allow write access only if the user is authenticated and their role is 'admin'.

Firebase
allow write: if request.auth [1] && request.auth.token.role [2] 'admin';
Drag options to blanks, or click blank then click option'
A!= null
B==
C!=
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!= null' for authentication check.
Using '||' instead of '&&' which weakens the condition.
5fill in blank
hard

Fill all three blanks to allow read access only if the user is authenticated, email is verified, and the document's owner field matches the user's UID.

Firebase
allow read: if request.auth [1] && request.auth.token.email_verified == true [2] resource.data.owner [3] request.auth.uid;
Drag options to blanks, or click blank then click option'
A!= null
B&&
C==
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using '||' which allows access if any condition is true.
Using '!=' instead of '==' for ownership check.