Skip to content

feat: Integrate Firebase Cloud Messaging (FCM) #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gsiddh
Copy link
Owner

@gsiddh gsiddh commented Aug 6, 2025

I've added Firebase Cloud Messaging capabilities to your web application.

Here are the key changes:

  • I created public/firebase-messaging-sw.js: This handles background notifications, initializing Firebase and displaying notifications when the app is not in focus.
  • I modified src/app.ts:
    • I integrated the FCM SDK to request notification permissions from you.
    • I retrieve and log/display the FCM registration token.
    • I added a handler for foreground messages, displaying them directly in the app.
    • I included a placeholder for the VAPID key, which you must configure.
  • I updated index.html:
    • I added new UI elements to display the FCM registration token and any notifications received while the app is in the foreground.

Here are the post-integration steps for you:

  • Replace the placeholder VAPID key in src/app.ts with your actual key from the Firebase console.
  • Ensure your Firebase project is configured for FCM, including the VAPID key.
  • Test by sending messages via the Firebase console.

I've added Firebase Cloud Messaging capabilities to your web application.

Here are the key changes:
- I created `public/firebase-messaging-sw.js`: This handles background notifications, initializing Firebase and displaying notifications when the app is not in focus.
- I modified `src/app.ts`:
    - I integrated the FCM SDK to request notification permissions from you.
    - I retrieve and log/display the FCM registration token.
    - I added a handler for foreground messages, displaying them directly in the app.
    - I included a placeholder for the VAPID key, which you must configure.
- I updated `index.html`:
    - I added new UI elements to display the FCM registration token and any notifications received while the app is in the foreground.

Here are the post-integration steps for you:
- Replace the placeholder VAPID key in `src/app.ts` with your actual key from the Firebase console.
- Ensure your Firebase project is configured for FCM, including the VAPID key.
- Test by sending messages via the Firebase console.
@gsiddh
Copy link
Owner Author

gsiddh commented Aug 6, 2025

@gemini-cli /review

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR integrates Firebase Cloud Messaging (FCM) into the application, enabling push notifications. The changes include a new service worker for background messages and updates to the main application to handle foreground messages and token management.

🔍 General Feedback

  • The implementation correctly sets up FCM and handles both background and foreground messages.
  • There are some security concerns with hardcoded keys and configurations that should be addressed.
  • The code could be made more maintainable by avoiding duplicated configurations.
  • The user experience for foreground messages can be improved by using a less intrusive notification method.


// Your web app's Firebase configuration (taken from src/app.ts)
// IMPORTANT: Make sure this config is identical to the one in src/app.ts
const firebaseConfig = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The firebaseConfig is duplicated from src/app.ts. This can lead to inconsistencies if the configuration changes in one place but not the other. Consider creating a shared configuration file and importing it in both src/app.ts and public/firebase-messaging-sw.js to avoid duplication and ensure consistency.

// IMPORTANT: Make sure this config is identical to the one in src/app.ts
const firebaseConfig = {
apiKey: "*", // Replace with your actual apiKey if not using a placeholder
authDomain: "vertexaiinfirebase-test.firebaseapp.com",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 The apiKey in firebaseConfig is hardcoded. This is a security risk. It should be loaded from a secure configuration or environment variables, not stored in a publicly accessible file.

Suggested change
authDomain: "vertexaiinfirebase-test.firebaseapp.com",
const firebaseConfig = {
apiKey: process.env.API_KEY, // Replace with your actual apiKey if not using a placeholder
authDomain: "vertexaiinfirebase-test.firebaseapp.com",
projectId: "vertexaiinfirebase-test",
storageBucket: "vertexaiinfirebase-test.firebasestorage.app",
messagingSenderId: "857620473716",
appId: "1:857620473716:web:8c803ada68ede9b2bb6e21"
};

// Example: Focus or open a window
// event.waitUntil(
// clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function(clientList) {
// if (clientList.length > 0) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 The notificationclick event listener contains commented-out code. If this functionality is intended to be used, it should be implemented. Otherwise, the commented-out code should be removed to improve code clarity and reduce clutter.

@gsiddh
Copy link
Owner Author

gsiddh commented Aug 6, 2025

@gemini-cli address feedback from the comments in this PR

Copy link

github-actions bot commented Aug 6, 2025

I've received your request and I'm working on it now! 🤖

Copy link

github-actions bot commented Aug 6, 2025

I am unable to see the comments in the PR. Could you please paste the comments here so I can address them?

@gsiddh
Copy link
Owner Author

gsiddh commented Aug 6, 2025

I am unable to see the comments in the PR. Could you please paste the comments here so I can address them?

@gemini-cli you should be able to see the comments. Please try again.

Copy link

github-actions bot commented Aug 6, 2025

I've received your request and I'm working on it now! 🤖

Copy link

github-actions bot commented Aug 6, 2025

I have retrieved the comments from the pull request. Here they are:

Review Summary by @github-actions

This PR integrates Firebase Cloud Messaging (FCM) into the application, enabling push notifications. The changes include a new service worker for background messages and updates to the main application to handle foreground messages and token management.

General Feedback

  • The implementation correctly sets up FCM and handles both background and foreground messages.
  • There are some security concerns with hardcoded keys and configurations that should be addressed.
  • The code could be made more maintainable by avoiding duplicated configurations.
  • The user experience for foreground messages can be improved by using a less intrusive notification method.

Other comments:

  • @gsiddh: @gemini-cli /review
  • @gsiddh: @gemini-cli address feedback from the comments in this PR
  • @github-actions: I've received your request and I'm working on it now! 🤖
  • @github-actions: I am unable to see the comments in the PR. Could you please paste the comments here so I can address them?
  • @gsiddh: > I am unable to see the comments in the PR. Could you please paste the comments here so I can address them?
    @gemini-cli you should be able to see the comments. Please try again.
  • @github-actions: I've received your request and I'm working on it now! 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant