convex-tenants
Multi-tenant organization and team management for Convex with @djpanda/convex-tenants and @djpanda/convex-authz. Use when (1) setting up or integrating multi-tenant SaaS with Convex, (2) working with organizations, teams, members, or invitations, (3) configuring authz permissions for tenants, (4) using TenantsProvider, OrganizationSwitcher, or related React components, or (5) the user mentions convex-tenants, @djpanda/convex-tenants, or multi-tenant Convex.
What this skill does
# Convex Tenants
Multi-tenant organization and team management for [Convex](https://convex.dev) with flexible authorization via `@djpanda/convex-authz`.
## Quick Start
1. **Register components** in `convex/convex.config.ts`:
```typescript
import { defineApp } from "convex/server";
import tenants from "@djpanda/convex-tenants/convex.config";
import authz from "@djpanda/convex-authz/convex.config";
const app = defineApp();
app.use(tenants);
app.use(authz);
export default app;
```
2. **Define authz** in `convex/authz.ts` — use `TENANTS_PERMISSIONS` and `TENANTS_ROLES` from the package. See `node_modules/@djpanda/convex-tenants/docs/quick-start.md`.
3. **Create tenants API** in `convex/tenants.ts`:
```typescript
import { makeTenantsAPI } from "@djpanda/convex-tenants";
import { components } from "./_generated/api";
import { authz } from "./authz";
export const { listOrganizations, createOrganization, inviteMember, ... } =
makeTenantsAPI(components.tenants, {
authz,
creatorRole: "owner",
auth: async (ctx) => (await getAuthUserId(ctx)) ?? null,
getUser: async (ctx, userId) => {
const user = await ctx.db.get(userId);
return user ? { name: user.name, email: user.email } : null;
},
});
```
4. **Use in React** — `useQuery(api.tenants.listOrganizations)`, or use pre-built components with `TenantsProvider`. See `node_modules/@djpanda/convex-tenants/docs/react-components.md`.
## Key Concepts
- **authz is a sibling component** — Register `authz` alongside `tenants`, not as a child. Other parts of your app can use authz outside tenants.
- **Roles are plain strings** — Define them in authz.ts. Default roles: `owner`, `admin`, `member`. See `node_modules/@djpanda/convex-tenants/docs/flexible-roles.md`.
- **Structural owner** — Each org has an `ownerId`. Use `transferOwnership` before owner leaves. All permission checks go through authz.
- **Organization status** — `suspended` or `archived` blocks mutations; only `updateOrganization` with `status: "active"` can reactivate.
## Exports
| Export | Description |
|--------|-------------|
| `TENANTS_PERMISSIONS` | Default permissions for `definePermissions()` |
| `TENANTS_ROLES` | Default roles (owner, admin, member) for `defineRoles()` |
| `DEFAULT_TENANTS_PERMISSION_MAP` | Operation → permission mapping |
| `TENANTS_REQUIRED_PERMISSIONS` | Flat list of permission strings |
## Documentation (read from package)
Base path: `node_modules/@djpanda/convex-tenants/docs/`. **Select the doc that matches the user's keywords or task** — load only what's needed:
| Doc | Path | Load when user asks about… |
|-----|------|----------------------------|
| **quick-start** | `docs/quick-start.md` | Setup, install, first-time integration, convex.config, authz.ts, tenants.ts, getting started, initial setup |
| **api-reference** | `docs/api-reference.md` | Function names (listOrganizations, createOrganization, addMember, inviteMember, etc.), makeTenantsAPI options, event hooks, mutation/query args, pagination (listMembers/listTeams/listTeamMembers/listInvitations with optional paginationOpts), API signatures |
| **permission-map** | `docs/permission-map.md` | Permissions, permissionMap, who can do what, operation permissions, overriding permissions, guards, access control per operation |
| **flexible-roles** | `docs/flexible-roles.md` | Roles, custom roles, owner/admin/member, creatorRole, defineRoles, structural owner, transferOwnership, add/remove roles |
| **invitation-system** | `docs/invitation-system.md` | Invitations, inviteMember, acceptInvitation, validateInvitationCreate, validateInvitationAccept, identifier type, email/phone/username, domain whitelist, rate limiting invitations |
| **react-components** | `docs/react-components.md` | TenantsProvider, OrganizationSwitcher, MembersSection, TeamsSection, InviteMemberDialog, useOrganization, useMembers, useTeams, useOrganizationInvitations, MembersTable, TeamsGrid, AcceptInvitation, JoinByDomainSection, paginated hooks |
| **organization-store** | `docs/organization-store.md` | Active organization, switching orgs, useOrganizationStore, setActiveOrganizationId, localStorage, storageKey, configureOrganizationStore |
## Installation
```bash
npm install @djpanda/convex-tenants @djpanda/convex-authz
```
For React UI: `npm install clsx tailwind-merge` (optional peer deps).
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.