mcpField
C
convex-tenants

convex-tenants

github.com/dbjpandaDevelopment11192 installsUpdated 24w ago
Repository

About convex-tenants

A Convex package for managing organizations, teams, memberships, and authorization in multi-tenant applications. It provides a configurable API and optional React components, with permissions handled through the sibling `@djpanda/convex-authz` component.

Key features

  1. 01Organization and team management
  2. 02Membership and invitation APIs
  3. 03Flexible roles and permission mapping
  4. 04Prebuilt React components and hooks

Use cases

  1. 01Adding organizations to a Convex application
  2. 02Managing team membership and invitations
  3. 03Building organization-switching interfaces

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/dbjpanda/convex-tenants --skill convex-tenants

After installing, type/convex-tenantsin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

api-reference.md
error-handling.md
flexible-roles.md
hooks-guide.md
invitation-system.md
known-limitations.md
organization-store.md
permission-map.md
quick-start.md
react-components.md
README.md
testing-guide.md

Details

From the project README

Convex Tenants

Multi-tenant organization and team management for Convex with flexible authorization via @djpanda/convex-authz.

Quick Start

  1. Register components in convex/convex.config.ts:
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;
  1. 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.

  2. Create tenants API in convex/tenants.ts:

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;
    },
  });
  1. 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

ExportDescription
TENANTS_PERMISSIONSDefault permissions for definePermissions()
TENANTS_ROLESDefault roles (owner, admin, member) for defineRoles()
DEFAULT_TENANTS_PERMISSION_MAPOperation → permission mapping
TENANTS_REQUIRED_PERMISSIONSFlat 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:

DocPathLoad when user asks about…
quick-startdocs/quick-start.mdSetup, install, first-time integration, convex.config, authz.ts, tenants.ts, getting started, initial setup
api-referencedocs/api-reference.mdFunction names (listOrganizations, createOrganization, addMember, inviteMember, etc.), makeTenantsAPI options, event hooks, mutation/query args, pagination (listMembers/listTeams/listTeamMembers/listInvitations with optional paginationOpts), API signatures
permission-mapdocs/permission-map.mdPermissions, permissionMap, who can do what, operation permissions, overriding permissions, guards, access control per operation
flexible-rolesdocs/flexible-roles.mdRoles, custom roles, owner/admin/member, creatorRole, defineRoles, structural owner, transferOwnership, add/remove roles
invitation-systemdocs/invitation-system.mdInvitations, inviteMember, acceptInvitation, validateInvitationCreate, validateInvitationAccept, identifier type, email/phone/username, domain whitelist, rate limiting invitations
react-componentsdocs/react-components.mdTenantsProvider, OrganizationSwitcher, MembersSection, TeamsSection, InviteMemberDialog, useOrganization, useMembers, useTeams, useOrganizationInvitations, MembersTable, TeamsGrid, AcceptInvitation, JoinByDomainSection, paginated hooks
organization-storedocs/organization-store.mdActive organization, switching orgs, useOrganizationStore, setActiveOrganizationId, localStorage, storageKey, configureOrganizationStore

Installation

npm install @djpanda/convex-tenants @djpanda/convex-authz

For React UI: npm install clsx tailwind-merge (optional peer deps).

Comments

Markdown supported