Skip to main content
This page covers registering devices from your client SDK. For the full feature overview — dashboard setup, server-side sending, and device lifecycle — see Push Notifications.
Requires the push bundle and configured provider credentials (APNs, FCM, or Web Push) in the dashboard. See the feature overview for setup.

Registering Devices

Use usePushRegistration with the adapter for your platform. Call register() in response to a deliberate user action — not on mount — because requesting OS push permission is a one-shot prompt that users cannot undo.
// Expo
import { usePushRegistration } from "@sublay/core";
import { expoPushTokenAdapter } from "@sublay/expo";

function SettingsScreen() {
  const { register, registering } = usePushRegistration(expoPushTokenAdapter);
  return <Button onPress={register} loading={registering} title="Enable notifications" />;
}
// Bare React Native
import { usePushRegistration } from "@sublay/core";
import { reactNativePushTokenAdapter } from "@sublay/react-native";

const { register } = usePushRegistration(reactNativePushTokenAdapter);
// Web (browser)
import { usePushRegistration } from "@sublay/core";
import { webPushTokenAdapter } from "@sublay/react-js";

const { register, unregister } = usePushRegistration(webPushTokenAdapter);
The web adapter requires a service worker. Register one before calling register(). The public VAPID key your service worker needs is available from the unauthenticated GET /vapid-public-key endpoint.

Unregistering on Logout

Call unregister() in your logout flow so the device stops receiving notifications after sign-out:
const { unregister } = usePushRegistration(webPushTokenAdapter);

async function handleLogout() {
  await unregister();
  // ...clear session
}

Next Steps

Feature Overview

Dashboard setup, sending, and device lifecycle

usePushRegistration

The full hook API and platform adapters