Announcements
In-app announcements for everyone, some tenants, some roles or some plans within a time window, with dismissals and a useAnnouncements hook over Realtime.
The announcements block shows banners such as "Scheduled maintenance
tonight" or "New: exports". Staff publish an announcement with an audience
and a time window; each user sees the live ones they haven't dismissed, and
open clients load the list again when one changes.
better-supabase add announcements # adds tenant and access as well| Table | Holds |
|---|---|
announcements | title, body, severity, href, audience and its targets, starts_at, ends_at, dismissible |
announcement_dismissals | Which user dismissed which announcement |
| Permission | Lets | Default roles |
|---|---|---|
announcements.manage | platform staff publish, change, archive, restore and purge | platform roles with it |
Audiences
| Audience | Who sees it |
|---|---|
{ type: "all" } | Every signed-in user |
{ type: "tenant", organizationIds: [...] } | Members of those organizations |
{ type: "role", roles: ["admin"] } | Members with one of those roles |
{ type: "plan", plans: ["pro"] } | Members of tenants with one of those entitlements |
Tenant, role and plan audiences match against the tenant the client passes, usually the active one; a tenant the user isn't a member of counts as none. The plan audience needs the entitlements module.
Publishing
Server code calls the announcements instance on db, in the caller's organization. With gen.hooks set, better-supabase gen writes the hooks:
export const { useList: useAnnouncements } = defineDataHooks(
"announcements",
(db: AppDb) => db.announcements,
);const rows = await db.announcements.list({ limit: 50 }).orThrow();"use client";
import { useAnnouncements } from "@/lib/supabase/hooks";
const rows = useAnnouncements({ limit: 50 });severity is info (the default), success, warning or critical.
href must start with https:// or /. The body is text you render; the
block doesn't interpret it.
Archiving and purging
archive takes an announcement out of listActive and list and keeps the row
and its dismissals; restore brings it back, and both record their event once
(announcement.archived, announcement.restored) and do nothing when the
announcement is already in that state. list({ includeArchived: true }) adds
the archived ones. purge removes the announcement and its dismissals for good
and records announcement.purged. It needs permissions.purge, which falls
back to announcements.manage until you set it. purge replaces remove
(ADR 1042).
await announcements.archive(notice.id).orThrow();
const all = await announcements.list({ includeArchived: true }).orThrow();
await announcements.purge(notice.id).orThrow();Showing them
const live = await announcements.listActive(organizationId).orThrow();
await announcements.dismiss(live[0].id);dismiss raises ANNOUNCEMENT_NOT_DISMISSIBLE for an announcement with
dismissible: false.
In Client Components, useAnnouncements loads the list and subscribes to
the private announcements topic. The module broadcasts there whenever an
announcement is published, changed, archived, restored or purged, and the hook loads the list
again. The hook is a registry item: install it with
npx shadcn add @better-supabase/use-announcements, which writes
hooks/use-announcements.ts into the app.
"use client";
import { useAnnouncements } from "@/hooks/use-announcements";
export function AnnouncementBar({
organizationId,
}: {
organizationId: string;
}) {
const { items, dismiss } = useAnnouncements({ organizationId });
return items?.map((item) => (
<div key={item.id} role="status" data-severity={item.severity}>
<strong>{item.title}</strong> {item.body}
{item.dismissible && (
<button onClick={() => dismiss(item.id)}>Dismiss</button>
)}
</div>
));
}Change the topic and the broadcast event with
blocks.announcements.options.topic and event, and pass the same
topic to the hook (null loads once without Realtime).
Vue
useBlockController from better-supabase/vue runs
createAnnouncementsController with its options; auth and ports come
from app.use(betterSupabase(bsb)) unless you pass them. state is a
shallow ref of the snapshot and actions are the controller's actions. The
work starts on mount, and the controller is disposed with the component.
<script setup lang="ts">
import { useBlockController, useSupabase } from "better-supabase/vue";
import {
createAnnouncements,
createAnnouncementsController,
rpcTransport,
} from "better-supabase/blocks/announcements";
const { organizationId } = defineProps<{ organizationId: string }>();
const supabase = useSupabase();
const { state } = useBlockController(createAnnouncementsController, {
client: createAnnouncements({ transport: rpcTransport(supabase) }),
organizationId,
});
</script>
<template>
<ul>
<li v-for="item in state.items ?? []" :key="item.id">{{ item.title }}</li>
</ul>
</template>Svelte
useBlockController from better-supabase/svelte runs
createAnnouncementsController with its options; auth and ports come
from setBetterSupabase(bsb) unless you pass them. It returns a readable
store of the snapshot, read with $, with the actions on
.actions. The work starts on mount, and the controller is disposed with
the component.
<script lang="ts">
import {
betterSupabase,
useBlockController,
} from "better-supabase/svelte";
import {
createAnnouncements,
createAnnouncementsController,
rpcTransport,
} from "better-supabase/blocks/announcements";
let { organizationId }: { organizationId: string } = $props();
const { supabase } = betterSupabase();
const announcements = useBlockController(createAnnouncementsController, {
client: createAnnouncements({ transport: rpcTransport(supabase) }),
organizationId,
});
</script>
<ul>
{#each $announcements.items ?? [] as item (item.id)}
<li>{item.title}</li>
{/each}
</ul>Solid
useBlockController from better-supabase/solid runs
createAnnouncementsController with its options; auth and ports come
from <BetterSupabaseProvider client={bsb}> unless you pass them.
state() reads the snapshot through from, and actions are the
controller's actions. The work starts on mount, and the controller is
disposed with the owner.
import { For } from "solid-js";
import { useBlockController, useSupabase } from "better-supabase/solid";
import {
createAnnouncements,
createAnnouncementsController,
rpcTransport,
} from "better-supabase/blocks/announcements";
export function Component(props: { organizationId: string }) {
const supabase = useSupabase();
const { state } = useBlockController(createAnnouncementsController, {
client: createAnnouncements({ transport: rpcTransport(supabase) }),
organizationId: props.organizationId,
});
return (
<ul>
<For each={state().items ?? []}>{(item) => <li>{item.title}</li>}</For>
</ul>
);
}Functions
| Function | Granted to | Does |
|---|---|---|
active_announcements(tenant) | authenticated, service_role | The caller's live, undismissed announcements |
dismiss_announcement(id) | authenticated, service_role | Hides one for the caller |
list_announcements(include_archived) | authenticated, service_role | Every announcement that is not archived, for staff; include_archived adds the archived ones |
upsert_announcement(id, fields) | authenticated, service_role | Creates (id null) or changes one, for staff |
archive_announcement(id) | authenticated, service_role | Takes one out of the lists, for staff |
restore_announcement(id) | authenticated, service_role | Brings an archived one back, for staff |
purge_announcement(id) | authenticated, service_role | Removes one and its dismissals for good, for staff |
Your own fields
Columns you add to announcements with alter table in your own schema files are fields of the block (details):,
keyed by column name with their SQL type. Pass createAnnouncements a Standard Schema
for them as fields: publish, update take them next to the block's own keys and
validate them (a bad value is a validation error), and listActive, list return them
parsed. A column the module already uses is refused. See
your own fields.
const client = createAnnouncements({
transport,
fields: z.object({ priority: z.number().int().positive().nullable() }),
});Without the client
db.announcements is this client. Code that does not go through bsb.db() builds it with a transport and an organization id:
import {
createAnnouncements,
sqlTransport,
} from "better-supabase/blocks/announcements";
const announcements = createAnnouncements({
transport: sqlTransport(postgres.admin),
});
const notice = await announcements
.publish({
title: "Scheduled maintenance",
body: "The app is read-only from 22:00 to 22:30 UTC.",
severity: "warning",
audience: { type: "all" },
startsAt: Temporal.Instant.from("2026-11-02T20:00:00Z"),
endsAt: Temporal.Instant.from("2026-11-02T22:30:00Z"),
dismissible: false,
})
.orThrow();
await announcements.update(notice.id, { body: "Moved to 23:00 UTC." });
await announcements.list();
await announcements.purge(notice.id);Paging announcements
page returns { items, hasMore, nextCursor } for the announcements a manager can see. Sorts are startsAt (the default, newest first), title and createdAt. Filters are severity, audience and archived (lists of values, a row matches any of them; archived: ["true"] adds archived rows), facets are severity and audience, and q searches the title and the body. facets counts each facet under the same filters, count returns { value, exact }, and get(announcementId) returns one announcement or a not_found error. The SQL functions are page_announcements and get_announcement.
const page = await announcements
.page({ filters: { severity: ["critical"] }, q: "maintenance", limit: 20 })
.orThrow();Last updated on
Waitlist
A waitlist with positions and approvals, hashed invite codes with use limits and an optional organization, and a before-user-created hook that makes sign-up invite-only.
Scores
Tenant-editable scoring models that add rule points and weighted metrics into a versioned score with bands on any record. Lead scoring and account health are models.