A. Missing permission request before calling getToken()
B. firebase.messaging() is not initialized
C. getToken() returns a promise, not a direct value
D. console.log() cannot print tokens
Solution
Step 1: Verify permission requirement
The code calls getToken() without first requesting notification permission using Notification.requestPermission().
Step 2: Consequence of missing permission
Without granted permission, messaging.getToken() rejects the promise with an error, leading to an unhandled promise rejection error.
Final Answer:
Missing permission request before calling getToken() -> Option A
Quick Check:
Permission before getToken() [OK]
Hint: Request permission with Notification.requestPermission() before getToken() [OK]
Common Mistakes:
Not using .then() or await with getToken()
Forgetting to initialize Firebase
Thinking console.log() cannot print tokens
5. You want to ensure your app always sends notifications to the correct device even if the FCM token changes. What is the best practice to handle token updates?
hard
A. Generate a new token manually every time the app starts
B. Store the token once and never update it
C. Listen for token refresh events and update your server with the new token
D. Ignore token changes because they rarely happen
Solution
Step 1: Understand token lifecycle
FCM tokens can change, so apps must detect and handle updates.
Step 2: Use token refresh listener
Listening for token refresh events lets the app send new tokens to the server to keep messaging accurate.
Final Answer:
Listen for token refresh events and update your server with the new token -> Option C
Quick Check:
Handle token refresh = update server [OK]
Hint: Always update server on token refresh events [OK]
Common Mistakes:
Storing token once without updates
Manually generating tokens incorrectly
Ignoring token changes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.