Establish the Better Auth session
db.auth, creates an organization, and calls db.auth.organization.setActive. The provider fetches the signed JWT used by live queries and mutations.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Follow the generated organization message app from session to live update.
const workerUrl = window.location.origin;
const db = createChardbReactClient({
url: workerUrl,
ownership: "organization",
auth: ({ baseURL }) => createAuthClient({
baseURL,
plugins: [anonymousClient(), organizationClient(), jwtClient()],
}),
});
<db.Provider>
<Workspace />
</db.Provider>
db.auth, creates an organization, and calls db.auth.organization.setActive. The provider fetches the signed JWT used by live queries and mutations.
const { data = [], state } = db.useQuery(listMessages, {
limit: 50,
});
const post = db.useMutation(postMessage);
const uploaded = selectedFile
? await attachment.upload({
file: selectedFile,
idempotencyKey: retryKey,
})
: null;
await post({
id: uuidv7(),
body,
attachment: uploaded?.fileId ?? null,
clientCreatedAt: Date.now(),
});