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:

  1. Requests push permission (PushNotifications.requestPermissions())
  2. Registers for push (PushNotifications.register()) if permission is granted
  3. 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 (addDevicePUT user/add_device)

Runtime events we listen to

Listeners registered in usePushNotifications:

  • registration: receives the device token
  • registrationError: logs registration errors
  • pushNotificationReceived: logs when a push is received
  • pushNotificationActionPerformed: 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)