FluxyChat

Getting Started

Quickstart

pk_ in the browser, then member JWT when the room is private.

First message

Public room first. No backend. Member JWT when the room is private or you need roles.

A. pk_ in the browser (about 30 seconds)

The room must be public. pk_ identifies the project. The SDK mints an anonymous guest JWT (POST /tokens/anonymous). Writes are on unless the operator set PUBLIC_GUEST_READ_ONLY.

pnpm add @fluxy-chat/react
import { FluxyRealtimeProvider, useChat } from "@fluxy-chat/react";

export function App() {
  return (
    <FluxyRealtimeProvider
      workerUrl="https://api.example.com"
      publishableKey="pk_..."
    >
      <Room />
    </FluxyRealtimeProvider>
  );
}

function Room() {
  const { messages, sendMessage, connectionState } = useChat({ roomId: "general" });
  return (
    <div>
      <p>Status: {connectionState.status}</p>
      <button type="button" onClick={() => sendMessage("Hello")}>Send</button>
      <ul>
        {messages.map((m) => (
          <li key={m.id ?? m.clientMessageId}>{m.content}</li>
        ))}
      </ul>
    </div>
  );
}

No useEffect. No joinPublicRoomAsGuest in the app. fc_ stays on the server.

Self-host without a pk_ row: FluxyChatClient.joinPublicRoomAsGuest(workerUrl, publicRoomId) still works when PUBLIC_GUEST_ENABLED is on.

Drop-in widget:

import { FluxyChatWidget } from "@fluxy-chat/ui-kit";

<FluxyChatWidget workerUrl={workerUrl} roomId="general" guest publishableKey="pk_..." />

B. CLI (hosted)

npx @fluxy-chat/create-fluxy-chat@latest my-app --mode hosted -y
cd my-app
pnpm install
pnpm setup:hosted
pnpm dev

Open http://localhost:5173, finish the tour, sign in. Mention @assistant in the room.

Self-host instead? Choose your path.

C. Member JWT (private rooms, roles, production)

FluxyRealtimeProvider takes workerUrl plus publishableKey, authTokenProvider, or connectUrl. It does not take a client prop. Nest FluxyYjsProvider inside it so it reuses that client (token still works).

Mint jwt on your server with POST /auth/token and a project API key (fc_…). Never put fc_… in the browser. See Auth JWT.

Local clone of this repo: pnpm run first-message prints a Worker URL and JWT for dev-local-general.

Next

On this page