Onboarding
Onboarding checklists per user or per organization, with steps completed by hand or by an outbox event, and a useOnboarding hook.
The onboarding block tracks getting-started checklists. You declare each
checklist once in the app with defineChecklist; the database stores which
steps each user, or each organization, has done. A step completes when the
app calls complete, or on its own when the outbox records one of the event
types it lists.
better-supabase add onboarding # adds tenant, access and enrollments as wellEach checklist runs on enrollments as the program
onboarding:<checklist>: the organization is enrolled in an organization
checklist, and each user, without an organization, in a user checklist. The
completed steps are enrollment_steps rows, so an admin page that lists
enrollments shows onboarding next to your own programs.
| Permission | Lets a member | Default roles |
|---|---|---|
onboarding.read | see an organization checklist's progress | owner, admin, member |
onboarding.complete | complete or reset an organization checklist's steps | owner, admin |
User checklists need no permission: each user reads and completes their own.
Checklists
import { defineChecklist } from "better-supabase/blocks/onboarding";
export const gettingStarted = defineChecklist({
id: "getting-started",
scope: "organization",
steps: [
{
id: "invite",
title: "Invite a teammate",
href: "/settings/members",
events: ["organization.member_added"],
},
{
id: "billing",
title: "Add a payment method",
href: "/settings/billing",
events: ["billing.subscription_updated"],
},
{ id: "project", title: "Create your first project" },
],
});Pass the checklists to the module, so its functions know the steps and the outbox trigger knows the event types:
import { gettingStarted } from "./src/onboarding.ts";
export default defineConfig({
blocks: { onboarding: { options: { checklists: [gettingStarted] } } },
});Steps with events need the outbox. An organization
step completes for the event's tenant; a user step completes for its actor.
Run better-supabase add onboarding again after you change a
checklist's steps. An enrollment takes the new steps the next time a step of
it completes or resets, and its progress counts only the current steps.
Progress
createOnboarding reads and completes the steps of any checklist the module
knows. Each method takes the checklist first, so its step ids are typed:
Server code calls the onboarding instance on db, in the caller's organization. With gen.hooks set, better-supabase gen writes the hooks:
export const { useList: useOnboarding } = defineDataHooks(
"onboarding",
(db: AppDb) => db.onboarding,
);const rows = await db.onboarding.list({ limit: 50 }).orThrow();"use client";
import { useOnboarding } from "@/lib/supabase/hooks";
const rows = useOnboarding({ limit: 50 });A user checklist takes no organization: onboarding.progress({ checklist: profile }).
complete returns false when the step was already done. With
defineBlocks, onboardingBlock builds the
same client, and hooks run around its methods:
const onboarding = createOnboarding({
transport,
hooks: {
complete: {
after: (result, [checklist, step]) => {
if (result.ok && result.data) track("step_done", checklist.id, step);
},
},
},
});The enrollments take no app columns: the steps live in defineChecklist.
In React
useOnboarding loads a checklist through the browser client and loads it
again after complete or reset. The hook is a registry item: install it
with npx shadcn add @better-supabase/use-onboarding, which writes
hooks/use-onboarding.ts into the app.
"use client";
import { useOnboarding } from "@/hooks/use-onboarding";
import { gettingStarted } from "@/onboarding";
export function GettingStarted({ organizationId }: { organizationId: string }) {
const { progress, complete } = useOnboarding(gettingStarted, {
organizationId,
});
if (!progress || progress.done) return null;
return (
<ol>
{progress.steps.map((step) => (
<li key={step.id}>
<a href={step.href}>{step.title}</a>
{step.completed ? (
" (done)"
) : (
<button onClick={() => complete(step.id)}>Mark done</button>
)}
</li>
))}
</ol>
);
}In Server Components, call onboarding.progress({ checklist }) instead; the hook
file starts with "use client".
Vue
useBlockController from better-supabase/vue runs
createOnboardingController with its options, as
Block controllers
explains; 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 {
createOnboarding,
createOnboardingController,
rpcTransport,
} from "better-supabase/blocks/onboarding";
import { gettingStarted } from "@/onboarding";
const { organizationId } = defineProps<{ organizationId: string }>();
const supabase = useSupabase();
const { state } = useBlockController(createOnboardingController, {
client: createOnboarding({ transport: rpcTransport(supabase) }),
checklist: gettingStarted,
organizationId,
});
</script>
<template>
<ul>
<li v-for="step in state.progress?.steps ?? []" :key="step.id">
{{ step.title }}
</li>
</ul>
</template>Svelte
useBlockController from better-supabase/svelte runs
createOnboardingController 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 {
createOnboarding,
createOnboardingController,
rpcTransport,
} from "better-supabase/blocks/onboarding";
import { gettingStarted } from "@/onboarding";
let { organizationId }: { organizationId: string } = $props();
const { supabase } = betterSupabase();
const onboarding = useBlockController(createOnboardingController, {
client: createOnboarding({ transport: rpcTransport(supabase) }),
checklist: gettingStarted,
organizationId,
});
</script>
<ul>
{#each $onboarding.progress?.steps ?? [] as step (step.id)}
<li>{step.title}</li>
{/each}
</ul>Solid
useBlockController from better-supabase/solid runs
createOnboardingController 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 {
createOnboarding,
createOnboardingController,
rpcTransport,
} from "better-supabase/blocks/onboarding";
import { gettingStarted } from "@/onboarding";
export function Component(props: { organizationId: string }) {
const supabase = useSupabase();
const { state } = useBlockController(createOnboardingController, {
client: createOnboarding({ transport: rpcTransport(supabase) }),
checklist: gettingStarted,
organizationId: props.organizationId,
});
return (
<ul>
<For each={state().progress?.steps ?? []}>
{(step) => <li>{step.title}</li>}
</For>
</ul>
);
}Functions
| Function | Granted to | Does |
|---|---|---|
onboarding_progress(checklist, tenant) | authenticated, service_role | The completed steps of a checklist |
complete_onboarding_step(checklist, step, tenant) | authenticated, service_role | Marks a step done; false when it already was |
reset_onboarding_step(checklist, step, tenant) | authenticated, service_role | Marks a step not done |
Unknown steps raise ONBOARDING_STEP_UNKNOWN, a tenant on a user checklist
(or none on an organization one) ONBOARDING_SCOPE, and a missing
permission ONBOARDING_FORBIDDEN.
Without the client
db.onboarding is this client. Code that does not go through bsb.db() builds it with a transport and an organization id:
import {
createOnboarding,
rpcTransport,
} from "better-supabase/blocks/onboarding";
import { gettingStarted } from "@/onboarding";
const onboarding = createOnboarding({ transport: rpcTransport(supabase) });
const progress = await onboarding
.progress({ checklist: gettingStarted, organizationId })
.orThrow();
// { steps: [{ id, title, completed, completedAt, ... }], completed: 1, total: 3, done: false, next: { id: "billing", ... } }
await onboarding.complete({
checklist: gettingStarted,
step: "project",
organizationId,
});
await onboarding.reset({
checklist: gettingStarted,
step: "project",
organizationId,
});Completing a step from one event
A step with completeOn: "invoice.sent" completes when the outbox records that event. It is the same as events: ["invoice.sent"], and the two can be combined. The event type uses the same rules as events.
Last updated on
Feature flags
Feature flags per tenant, per user and per custom context such as a brand, with targeting rules, overrides and percentage rollouts, evaluated the same way in RLS, in an OpenFeature provider and in the Flags SDK.
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.