gitroomhq/postiz-app · warning · HttpException

User is already a member of this organization

Error message

User is already a member of this organization

What it means

Thrown as HTTP 400 when the resolved user is already a member of the target organization (their org list contains org.id). Prevents duplicate memberships.

Source

Thrown at libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts:138

    );
    if (!users.length) {
      throw new HttpException('No Postiz account found for this email', 400);
    }

    if (users.length > 1) {
      throw new HttpException(
        'Multiple accounts exist for this email (different login providers)',
        400
      );
    }

    const [user] = users;

    const userOrgs = await this._organizationRepository.getOrgsByUserId(
      user.id
    );
    if (userOrgs.some((current) => current.id === org.id)) {
      throw new HttpException(
        'User is already a member of this organization',
        400
      );
    }

    const added = await this._organizationRepository.addUserToOrg(
      user.id,
      makeId(5),
      org.id,
      body.role as 'USER' | 'ADMIN'
    );

    if (!added) {
      throw new HttpException(
        'Could not add the user to the organization',
        400
      );
    }

View on GitHub (pinned to 0f1647f749)

Solutions

  1. Refresh the organization member list and skip the invite if present
  2. Disable the invite button while the request is in flight and after success
  3. Treat this error as a no-op success in idempotent invite flows

Example fix

// before
await addTeamMember(orgId, email);
// after
const members = await listMembers(orgId);
if (!members.some((m) => m.email === email)) {
  await addTeamMember(orgId, email);
}
Defensive patterns

Strategy: validation

Validate before calling

const members = await listMembers(orgId);
if (members.some((m) => m.userId === user.id)) return; // already member

Type guard

const isAlreadyMember = (orgs: {id: string}[], orgId: string): boolean => orgs.some((o) => o.id === orgId);

Try / catch

try { await addTeamMember(orgId, email); } catch (e) { if (/already a member/.test(e.message)) return { added: true }; throw e; }

Prevention

When it happens

Trigger: Re-sending an invite for a user who already accepted; user already belongs via a previous invite; UI state stale so the member list doesn't show them.

Common situations: Invitee clicked the invite twice; org list not refreshed after adding; frontend allows repeated submits (double-click, retry); user was added programmatically elsewhere.

Related errors


AI-assisted analysis of gitroomhq/postiz-app@0f1647f749 (2026-08-27). Data as JSON: /api/errors/d6d8b87035aa92b1. Report an issue: GitHub.