-
Notifications
You must be signed in to change notification settings - Fork 4
Notification done #36
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
base: main
Are you sure you want to change the base?
Conversation
🔍 Code Review Summary❗ Attention Required: This push has potential issues. 🚨 Overview
🚨 Critical Issuessecurity (1 issues)1. Hardcoded application server key in service worker.📁 File: apps/pwa/src/sw.ts 💡 Solution: Current Code: applicationServerKey: 'BLA70jg5Wgi6XD6BAElOfW7YXcQ3l3iFRzyPj5AV5ZuSr_uTugv-9hbgXwfPhuw_JfbDAqn-Fl5nKSvnQpjFV8g',Suggested Code: applicationServerKey: env.VAPID_PUBLIC_KEY,
Useful Commands
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider implementing the following changes to improve the code.
| // Proceed with subscription if not already subscribed | ||
| const registration = await navigator.serviceWorker.ready; | ||
| const subscription = await registration.pushManager.subscribe({ | ||
| userVisibleOnly: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: Hardcoded application server key in service worker.
Solution: Store sensitive keys in environment variables and access them securely.
Potential Fix:
applicationServerKey: env.VAPID_PUBLIC_KEY,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be trpc routes.
| export function addSubscription(subscription: PushSubscription) { | ||
| pushSubscriptions.add(subscription); | ||
| } | ||
|
|
||
| export function removeSubscription(subscription: PushSubscription) { | ||
| pushSubscriptions.delete(subscription); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If multiple instances of backend are running in production, this will lead to same notification being sent to user multiple times.
| // Schedule a notification every 5 seconds | ||
| export function scheduleFrequentNotification() { | ||
| scheduleJob('*/5 * * * * *', async () => { | ||
| console.log('Sending notification'); | ||
| await sendNotificationToAll('Frequent Update', 'Here is your notification every 5 seconds!'); | ||
| }); | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand you needed this for dev, but then have guardrails to run only in isDev
| const registration = await navigator.serviceWorker.ready; | ||
| const subscription = await registration.pushManager.subscribe({ | ||
| userVisibleOnly: true, | ||
| applicationServerKey: 'BLA70jg5Wgi6XD6BAElOfW7YXcQ3l3iFRzyPj5AV5ZuSr_uTugv-9hbgXwfPhuw_JfbDAqn-Fl5nKSvnQpjFV8g', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please pick this from env
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seperate SW config from vite config. & add comments with examples on impact/importance for specific fields in config.
Comprehensive Update on Push Notifications and Service Worker Enhancements
Implement push notifications and service worker updates for the PWA application.
web-pushlibrary.vite-plugin-pwafor managing service worker and PWA manifest.node-scheduleandweb-push.antd,react-toastify, andworkbox-core.node-scheduleandweb-push.Users will receive push notifications, enhancing engagement, while the application will automatically update, improving overall user experience.
Original Description
# Add Push Notification Functionality**
Implement push notification capabilities in the API server and PWA client.
node-scheduleandweb-pushdependencies to handle scheduling and sending push notifications.**
Users will be able to subscribe to push notifications and receive real-time updates from the application.
Original Description