# Live updates for Refine admin panels

> A liveProvider for Refine: lists, records and dashboards update by themselves when someone else changes the data. Refine 4 and 5, any UI kit and any data provider.

Source: https://hibira.io/guides/refine

A liveProvider for Refine: lists, records and dashboards update by themselves when someone else changes the data. Refine 4 and 5, any UI kit and any data provider.

Package: @hibira-io/refine

- useList, useOne, useTable, useForm and useShow refetch on their own with liveMode: "auto".
- Private channels with your own auth endpoint, and hooks on the same resource share one subscription.
- publishLiveEvent() sends events from your API after each change and can leave out the tab that made it.

## 1. Install

```shell
npm install @hibira-io/refine pusher-js
# on your backend
npm install pusher
```

## 2. Set it up

```tsx
import { Refine } from '@refinedev/core';
import Pusher from 'pusher-js';
import { liveProvider } from '@hibira-io/refine';

const pusher = new Pusher(import.meta.env.VITE_HIBIRA_KEY, {
  cluster: 'hkg',
  wsHost: 'ws.hibira.io',
  channelAuthorization: { endpoint: '/api/hibira/auth', transport: 'ajax' },
});

export const App = () => (
  <Refine
    dataProvider={dataProvider}
    liveProvider={liveProvider(pusher, { channelPrefix: 'private-', publish: false })}
    options={{ liveMode: 'auto' }}
  />
);
```

## 3. Use it

```ts
import Pusher from 'pusher';
import { publishLiveEvent } from '@hibira-io/refine/server';

const pusher = new Pusher({
  appId: process.env.HIBIRA_APP_ID!,
  key: process.env.HIBIRA_KEY!,
  secret: process.env.HIBIRA_SECRET!,
  host: 'ws.hibira.io',
  useTLS: true,
});

// after updating post 42
await publishLiveEvent(pusher, { resource: 'posts', type: 'updated', ids: [42] }, { channelPrefix: 'private-', socketId: req.headers['x-socket-id'] });
```

## Before you start

- Private and presence channels need an auth endpoint on your backend that signs subscriptions with the app secret, as with pusher-js.
- Laravel can send the same events: broadcast "refine" on resources.posts with a body shaped like a Refine LiveEvent.

- [npm](https://www.npmjs.com/package/@hibira-io/refine)
- [GitHub](https://github.com/hibira-io/refine)
