Skip to main content

Overview

The Families API enables multi-caregiver collaboration. Families group users together with role-based permissions to share access to baby profiles and activities.

Family Schema

interface Family {
  _id: Id<"families">;
  name: string;
  ownerId: string; // User ID of family owner
  createdAt: string;
}

interface FamilyMember {
  _id: Id<"familyMembers">;
  familyId: Id<"families">;
  userId: string;
  role: "owner" | "admin" | "caregiver";
  joinedAt: string;
}

interface FamilyInvitation {
  _id: Id<"familyInvitations">;
  familyId: Id<"families">;
  email: string;
  role: string;
  invitedBy: string;
  status: "pending" | "accepted" | "declined" | "expired";
  createdAt: string;
  expiresAt: string;
}

Create Family

Create a new family. The authenticated user automatically becomes the owner.
import { useMutation } from "convex/react";
import { api } from "./convex/_generated/api";

const createFamily = useMutation(api.families.createFamily);

const familyId = await createFamily({
  name: "Smith Family"
});

Parameters

name
string
required
Family name (e.g., “Smith Family”, “Grandparents”)

Response

familyId
Id<'families'>
The newly created family ID
The creating user is automatically added as a family member with the “owner” role and cannot be removed.

List My Families

Retrieve all families the authenticated user belongs to.
const families = useQuery(api.families.listMyFamilies);

// Response:
[
  {
    _id: "...",
    name: "Smith Family",
    ownerId: "user123",
    createdAt: "2024-03-05T10:00:00Z",
    role: "owner" // Current user's role
  }
]

Response

families
array
Array of family objects with the user’s role included

Get Family

Retrieve details for a specific family.
const family = useQuery(api.families.getFamily, {
  familyId
});

Parameters

familyId
Id<'families'>
required
The family ID

Response

Returns the family object with the user’s role, or null if not a member.

List Family Members

Retrieve all members of a family.
const members = useQuery(api.families.listFamilyMembers, {
  familyId
});

// Response:
[
  {
    _id: "...",
    familyId: "...",
    userId: "user123",
    role: "owner",
    joinedAt: "2024-03-05T10:00:00Z",
    userName: "John Smith",
    userEmail: "[email protected]"
  }
]

Parameters

familyId
Id<'families'>
required
The family ID

Response

members
array
Array of family member objects with enriched user data

Invite Caregiver

Invite a new member to the family by email.
const inviteCaregiver = useMutation(api.families.inviteCaregiver);

await inviteCaregiver({
  familyId,
  email: "[email protected]",
  role: "caregiver" // optional, defaults to "caregiver"
});

Parameters

familyId
Id<'families'>
required
The family ID
email
string
required
Email address of the person to invite
role
string
Role to assign (“admin” or “caregiver”). Defaults to “caregiver”
Only owners and admins can invite new members. Attempting to invite as a caregiver will throw an error.

Response

inviteId
Id<'familyInvitations'>
The created invitation ID
Invitations expire after 7 days. The invitee must accept before expiration.

List Invitations

Retrieve pending invitations for a family.
const invitations = useQuery(api.families.listInvitations, {
  familyId
});

Parameters

familyId
Id<'families'>
required
The family ID

Response

[
  {
    _id: "...",
    familyId: "...",
    email: "[email protected]",
    role: "caregiver",
    status: "pending",
    invitedBy: "user123",
    createdAt: "2024-03-05T10:00:00Z",
    expiresAt: "2024-03-12T10:00:00Z"
  }
]

Accept Invitation

Accept a pending invitation (called by the invitee).
const acceptInvitation = useMutation(api.families.acceptInvitation);

await acceptInvitation({
  invitationId
});

Parameters

invitationId
Id<'familyInvitations'>
required
The invitation ID
The authenticated user’s email must match the invitation email. The invitation is automatically marked as accepted and the user is added to the family.

Decline Invitation

Decline a pending invitation.
const declineInvitation = useMutation(api.families.declineInvitation);

await declineInvitation({
  invitationId
});

Parameters

invitationId
Id<'familyInvitations'>
required
The invitation ID

Remove Member

Remove a member from the family.
const removeMember = useMutation(api.families.removeMember);

await removeMember({
  familyId,
  userId: "userToRemove"
});

Parameters

familyId
Id<'families'>
required
The family ID
userId
string
required
User ID of the member to remove
  • Only owners and admins can remove members
  • The family owner cannot be removed
  • Admins cannot remove other admins or the owner

Role Permissions

Full Control
  • Create and delete baby profiles
  • Invite and remove any member
  • Change member roles
  • Delete the family
  • All caregiver and admin permissions
Every family has exactly one owner who cannot be removed.

Best Practices

Choose clear names like “Grandparents” or “Daycare Staff” to help members identify their role and context.
  • Owner: Primary parent/guardian
  • Admin: Co-parent or primary caregiver
  • Caregiver: Babysitters, grandparents, daycare staff
Invitations expire after 7 days. Follow up with invitees to ensure they accept in time.
Remove members who no longer need access to maintain security and data privacy.

Caregivers

Learn about caregiver profiles and attribution

Roles

Detailed role permissions guide

Baby Profiles

Manage baby profiles within families

Authentication

API authentication guide

Build docs developers (and LLMs) love