Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the Firebase Admin SDK.
Firebase
const admin = require('firebase-admin'); admin.[1]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist like startApp or launchApp.
Forgetting to call the method as a function.
✗ Incorrect
The initializeApp() method starts the Firebase Admin SDK so you can use its services.
2fill in blank
mediumComplete the code to get a Firestore database instance.
Firebase
const db = admin.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using getFirestore() which is not a method on admin directly.
Using database() which is for Realtime Database, not Firestore.
✗ Incorrect
The firestore() method returns the Firestore database instance from the Admin SDK.
3fill in blank
hardFix the error in the code to send a message using Firebase Cloud Messaging.
Firebase
const message = { token: userToken, notification: { title: 'Hello', body: 'World' } };
admin.messaging().[1](message)
.then(response => console.log('Sent:', response))
.catch(error => console.error('Error:', error)); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendMessage which does not exist in the Admin SDK.
Using publish or dispatch which are not Firebase methods.
✗ Incorrect
The correct method to send a message with Firebase Cloud Messaging is send().
4fill in blank
hardFill in the blank to create a new user with email and password using Firebase Admin SDK.
Firebase
admin.auth().[1]({ email: userEmail, password: userPassword }) .then(userRecord => console.log('User created:', userRecord.uid)) .catch(error => console.error('Error:', error));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addUser or registerUser which are not valid Admin SDK methods.
Using newUser which does not exist.
✗ Incorrect
The method to create a new user is createUser().
5fill in blank
hardFill in the two blanks to update a user's display name and photo URL.
Firebase
admin.auth().updateUser(userId, { displayName: [1], photoURL: [2] })
.then(userRecord => console.log('Updated user:', userRecord.uid))
.catch(error => console.error('Error:', error)); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using userId as a value for displayName or photoURL.
Not using quotes around string values.
✗ Incorrect
To update user profile fields, provide string values for displayName and photoURL.