Overview
Explicit, developer-triggered hook for registering and unregistering the current user’s device for push notifications. Unlike auth-token restoration, requesting OS or browser push permission is a deliberate action and should happen in response to a user gesture (for example, when they opt in to notifications in your settings screen) — not silently on mount. The hook accepts a platform adapter that abstracts the platform-specific permission and token-retrieval steps. Three adapters are available out of the box:| Adapter | Package | Platform |
|---|---|---|
expoPushTokenAdapter | @sublay/expo | Expo (iOS + Android) |
reactNativePushTokenAdapter | @sublay/react-native | Bare React Native (iOS + Android) |
webPushTokenAdapter | @sublay/react-js | Browser (Web Push) |
Usage Example
Parameters
A platform adapter implementing
requestPermission() and getDeviceIdentifier(). Import one of the three built-in adapters or implement your own.Returns
Requests OS or browser permission, retrieves the device token or subscription, and registers it with the server. Returns
true on success, false if permission was denied or the adapter could not produce an identifier (both are expected outcomes, not errors). Throws when the server call fails.Retrieves the current device identifier and removes the registration from the server. A no-op if the adapter returns no identifier.
true while register() is in progress.true while unregister() is in progress.The hook requires an authenticated user —
register() and unregister() throw immediately if no user session is available.Platform Adapters
expoPushTokenAdapter (@sublay/expo)
Uses expo-notifications to request permission and retrieve the raw APNs/FCM device token directly (not the Expo relay token — Sublay dispatches to APNs and FCM using the project’s own credentials).
expo-notifications in your project.
reactNativePushTokenAdapter (@sublay/react-native)
Uses @react-native-firebase/messaging for both iOS and Android. On iOS, getAPNSToken() returns the raw APNs token; on Android, getToken() returns the FCM registration token.
@react-native-firebase/messaging and the native Firebase setup for your platform (GoogleService-Info.plist / google-services.json).
webPushTokenAdapter (@sublay/react-js)
Uses the browser’s Notification permission API and Push API. Fetches the project’s VAPID public key from the server (unauthenticated), then calls PushManager.subscribe() to create a Web Push subscription. Requires a service worker registered on your page.
false (without throwing) in environments where the Notification or Push APIs are unavailable (for example, SSR).
Custom Adapters
ImplementPushTokenAdapter from @sublay/core to use your own push library:

