0
0
Firebasecloud~10 mins

Multi-tenancy 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 initialize Firebase for a specific tenant.

Firebase
const app = initializeApp({ projectId: [1] });
Drag options to blanks, or click blank then click option'
A'shared_project'
B'tenant_project_123'
C'default_project'
D'global_project'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a shared or global project ID which mixes tenant data.
Using the default project which is not tenant-specific.
2fill in blank
medium

Complete the code to set Firestore rules for tenant data isolation.

Firebase
match /databases/{database}/documents {
  match /users/{userId} {
    allow read, write: if request.auth.token.[1] == userId;
  }
}
Drag options to blanks, or click blank then click option'
Aemail
BtenantId
Crole
Duid
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tenantId' which is not a standard auth token property.
Using 'email' which is not a secure identifier for rules.
3fill in blank
hard

Fix the error in the Firestore query to fetch tenant-specific data.

Firebase
const query = firestore.collection('orders').where('tenantId', '==', [1]);
Drag options to blanks, or click blank then click option'
A'tenantId'
Btenant_id
CtenantId
Dtenant
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the field name inside the where method parameter.
Using incorrect field names like 'tenant_id' or 'tenant'.
4fill in blank
hard

Fill both blanks to create a Firestore document path for tenant data isolation.

Firebase
const docRef = firestore.collection([1]).doc([2]);
Drag options to blanks, or click blank then click option'
A'tenants'
B'tenantId'
C'users'
D'userId'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing collection and document names incorrectly.
Using 'tenantId' as a document ID instead of 'userId'.
5fill in blank
hard

Fill all three blanks to define a Firestore security rule for multi-tenant data access.

Firebase
match /[1]/{docId} {
  allow read, write: if request.auth.token.[2] == resource.data.[3];
}
Drag options to blanks, or click blank then click option'
Atenants
BtenantId
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'users' instead of 'tenants' in the match path.
Mismatching token and data field names.