# Subjects

> The app-wide subject registry from config.recordTypes: subject_title, subject_url, subject_titles, can_subject, can_subject_for and record_summary for every registered type, my_work across the installed blocks, record teams (subject_members, create_subject_member, end_subject_member, list_subject_members, my_subjects) that grant subjects.<type>.team actions, read logging for types with subjects.<type>.auditReads (record_subject_read, subject_access_log), and Realtime presence on presence:<type>:<id> for readers of the subject.

- Category: Identity & access
- Module: `subjects`
- Modes: `managed`, `custom`
- Docs: https://bettersupabase.com/docs/blocks/subjects
- Page: https://bettersupabase.com/blocks/subjects

## Install

```bash
npx better-supabase add subjects
```

The command also installs `updated-at`, `memberships`, `permissions`.

## Configure

Add the block to `better-supabase.config.ts`:

```ts
import { defineConfig } from "better-supabase/config";

export default defineConfig({
  blocks: {
    // Required by subjects; add installs them too.
    "updated-at": {},
    memberships: {},
    permissions: {},
    // Modes: "managed", "custom". The default is "managed".
    subjects: { mode: "managed" },
  },
});
```

## Client

The React hooks are the registry item `@better-supabase/use-subjects` (`npx shadcn add @better-supabase/use-subjects`). They return data and actions and render no UI. Source: https://github.com/ScaleDockHQ/better-supabase/blob/main/packages/registry/items/hooks/use-subjects.ts

## Events

- `subject_member.added`
- `subject_member.ended`

## Related blocks

Requires: [permissions](https://bettersupabase.com/blocks/permissions.md)

Works with: [teams](https://bettersupabase.com/blocks/teams.md), [memberships](https://bettersupabase.com/blocks/memberships.md), [audit](https://bettersupabase.com/blocks/audit.md), [relations](https://bettersupabase.com/blocks/relations.md)

## Recipes

- [Subject link](https://bettersupabase.com/recipes/subject-link.md): A link to any subject type, titled and routed by subject_titles, with plain text for a record the caller can't read.
- [Subject chip](https://bettersupabase.com/recipes/subject-chip.md): A compact badge with a subject's type and title that links to its page.
- [My work](https://bettersupabase.com/recipes/my-work.md): What waits on the caller across the installed blocks, from `getMyWork`: assigned work, approvals, due reminders, mentions and SLA warnings, each linked to its record.
