{"record":{"id":"d6d8b87035aa92b1","repo":"gitroomhq/postiz-app","slug":"user-is-already-a-member-of-this-organization","errorCode":null,"errorMessage":"User is already a member of this organization","messagePattern":"User is already a member of this organization","errorType":"http","errorClass":"HttpException","httpStatus":400,"severity":"warning","filePath":"libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts","lineNumber":138,"sourceCode":"    );\n    if (!users.length) {\n      throw new HttpException('No Postiz account found for this email', 400);\n    }\n\n    if (users.length > 1) {\n      throw new HttpException(\n        'Multiple accounts exist for this email (different login providers)',\n        400\n      );\n    }\n\n    const [user] = users;\n\n    const userOrgs = await this._organizationRepository.getOrgsByUserId(\n      user.id\n    );\n    if (userOrgs.some((current) => current.id === org.id)) {\n      throw new HttpException(\n        'User is already a member of this organization',\n        400\n      );\n    }\n\n    const added = await this._organizationRepository.addUserToOrg(\n      user.id,\n      makeId(5),\n      org.id,\n      body.role as 'USER' | 'ADMIN'\n    );\n\n    if (!added) {\n      throw new HttpException(\n        'Could not add the user to the organization',\n        400\n      );\n    }","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/gitroomhq/postiz-app/blob/0f1647f7491a217d43eb5ae7a480484bdf0aff3e/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts#L120-L156","documentation":"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.","triggerScenarios":"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.","commonSituations":"Invitee clicked the invite twice; org list not refreshed after adding; frontend allows repeated submits (double-click, retry); user was added programmatically elsewhere.","solutions":["Refresh the organization member list and skip the invite if present","Disable the invite button while the request is in flight and after success","Treat this error as a no-op success in idempotent invite flows"],"exampleFix":"// before\nawait addTeamMember(orgId, email);\n// after\nconst members = await listMembers(orgId);\nif (!members.some((m) => m.email === email)) {\n  await addTeamMember(orgId, email);\n}","handlingStrategy":"validation","validationCode":"const members = await listMembers(orgId);\nif (members.some((m) => m.userId === user.id)) return; // already member","typeGuard":"const isAlreadyMember = (orgs: {id: string}[], orgId: string): boolean => orgs.some((o) => o.id === orgId);","tryCatchPattern":"try { await addTeamMember(orgId, email); } catch (e) { if (/already a member/.test(e.message)) return { added: true }; throw e; }","preventionTips":["Refresh the member list before showing invite buttons","Make invite submission idempotent (disable while in-flight)"],"tags":["team-members","duplicate","invite"],"backgroundTag":"duplicate-member-invite","analyzedSha":"0f1647f7491a217d43eb5ae7a480484bdf0aff3e","analyzedAt":"2026-08-27T12:09:55.020Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}