0
0
Firebasecloud~10 mins

Custom functions in 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 define a custom function named isOwner.

Firebase
function [1](userId) {
  return request.auth.uid == userId;
}
Drag options to blanks, or click blank then click option'
AcheckUser
BisOwner
CvalidateUser
DownerCheck
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that does not match the rule call.
Misspelling the function name.
2fill in blank
medium

Complete the code to call the custom function isOwner inside the rule.

Firebase
allow read: if [1](resource.data.ownerId);
Drag options to blanks, or click blank then click option'
AisOwner
BcheckUser
CvalidateUser
DownerCheck
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function name that was not defined.
Forgetting to pass the ownerId parameter.
3fill in blank
hard

Fix the error in the custom function to correctly check if the user is authenticated.

Firebase
function isOwner(userId) {
  return [1] != null && request.auth.uid == userId;
}
Drag options to blanks, or click blank then click option'
Arequest.auth.uid
Brequest.auth.token
Crequest.auth
Drequest.auth.id
Attempts:
3 left
💡 Hint
Common Mistakes
Checking only request.auth.uid without verifying auth exists.
Using incorrect property names like request.auth.id.
4fill in blank
hard

Fill both blanks to define a custom function that checks if the user is an admin or the owner.

Firebase
function [1](userId) {
  return request.auth != null && (request.auth.token.admin == true || request.auth.uid == [2]);
}
Drag options to blanks, or click blank then click option'
AisAdminOrOwner
BuserId
CownerId
DisOwner
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names that do not describe the check.
Using wrong variable names inside the function.
5fill in blank
hard

Fill the blanks to write a rule that allows write if the user is admin or owner using the custom function.

Firebase
allow write: if [1](resource.data.[2]);
Drag options to blanks, or click blank then click option'
AisAdminOrOwner
BownerId
Cadmin
DisOwner
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong function name in the rule.
Using incorrect data field names.