Push
Overview
The utils.push.js module provides a helper for subscribing the current device to web push notifications. It integrates with the feathers-webpush client library and requires the application to run in PWA mode.
Functions
async subscribeToPushNotifications()
Subscribes the current device to web push notifications and registers the subscription with the authenticated user's account.
Flow:
- Checks that the application is running in PWA mode — aborts if not.
- Calls
checkPrerequisites()andrequestNotificationPermission()— shows an error notification and aborts if either fails. - If the device is already subscribed (matching endpoint found in
user.subscriptions), updates thelastActivitytimestamp only. - Otherwise, creates a new push subscription using the server's VAPID public key, enriches it with device metadata (fingerprint, browser, OS,
lastActivity), and patches the user'ssubscriptionsarray.
- Returns:
Promise<void> - Requires: The user must be authenticated before calling this function. The
capabilities.api.vapidPublicKeymust be available in the global store.
javascript
import { subscribeToPushNotifications } from '@kalisio/kdk/core.client'
// e.g. called when the user enables push notifications
await subscribeToPushNotifications()