BuildBaseBuildBase

Overview

Add browser push notifications with PushNotificationProvider and usePushNotifications.

BuildBase provides browser push notifications out of the box. Wrap your app in PushNotificationProvider, then use usePushNotifications() to manage permission and subscription state.

import { PushNotificationProvider } from '@buildbase/sdk/react';

function App() {
  return (
    <PushNotificationProvider>
      <Dashboard />
    </PushNotificationProvider>
  );
}
import { usePushNotifications } from '@buildbase/sdk/react';

function NotificationBell() {
  const {
    permission,
    isSubscribed,
    requestPermission,
    subscribe,
    unsubscribe,
  } = usePushNotifications();

  if (permission === 'denied') return <p>Notifications blocked.</p>;

  if (!isSubscribed) {
    return (
      <button
        onClick={async () => {
          await requestPermission();
          await subscribe();
        }}
      >
        Enable notifications
      </button>
    );
  }

  return <button onClick={unsubscribe}>Disable notifications</button>;
}

PushNotificationProvider props

PropTypeDefaultDescription
serviceWorkerPathstring'/push-sw.js'Path to the push service worker
autoSubscribebooleanfalseAuto-subscribe after permission granted

usePushNotifications() returns

ReturnTypeDescription
permission'default' / 'granted' / 'denied'Browser notification permission
isSubscribedbooleanWhether the device is subscribed
isSupportedbooleanWhether the browser supports push
loadingbooleanLoading state
requestPermission()functionRequest notification permission
subscribe()functionSubscribe to push notifications
unsubscribe()functionUnsubscribe

Sending notifications (server-side)

Use the server SDK to send notifications to users:

import BuildBase from '@buildbase/sdk';

const bb = BuildBase({ serverUrl, orgId, getSessionId });

// Send to a specific user
await bb.notification.send(workspaceId, 'comment-added', userId, {
  title: 'New comment',
  message: 'Someone commented on your post.',
  url: '/posts/123',
});

// Send to all workspace members
await bb.notification.send(workspaceId, 'new-release');

Next Steps

  • Webhooks — React to events server-side.
  • Server SDK — All server methods including notifications.