Push notifications
Push notifications are handled via the Capacitor Push Notifications plugin (@capacitor/push-notifications).
Where it’s implemented
- Hook:
client/src/components/notifications/PushNotifications.js(usePushNotifications)
What happens on login
When the user is logged in, the hook:
- Requests push permission (
PushNotifications.requestPermissions()) - Registers for push (
PushNotifications.register()) if permission is granted - Listens for the device token and sends it to the backend:
- event:
registration - call:
addDevice(authCtx.tokens.idToken, token.value) - endpoint wrapper:
client/src/global/request/user.js(addDevice→PUT user/add_device)
- event:
Runtime events we listen to
Listeners registered in usePushNotifications:
registration: receives the device tokenregistrationError: logs registration errorspushNotificationReceived: logs when a push is receivedpushNotificationActionPerformed: logs when the user taps an action / notification
Android notes (Firebase)
Android includes Firebase Messaging in client/android/app/build.gradle:
com.google.firebase:firebase-messaging
The Gradle file only applies the Google Services plugin if google-services.json exists, otherwise it logs that push notifications won’t work.
Testing
- Push notifications require a native build (Capacitor). They won’t work in the browser.
- After installing the app on a device, sign in and confirm:
- permission prompt appears (or is already granted)
- backend has the device token associated with the user (via
user/add_device)