gitroomhq/postiz-app · error · Error
User is not part of this organization
Error message
User is not part of this organization
What it means
Thrown as a plain Error (resulting in HTTP 500 unless caught) when deleting a team member whose user-organization record doesn't include the target org — i.e. the userId is not a member of this organization at all.
Source
Thrown at libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts:165
org.id,
body.role as 'USER' | 'ADMIN'
);
if (!added) {
throw new HttpException(
'Could not add the user to the organization',
400
);
}
return { added: true };
}
async deleteTeamMember(org: Organization, userId: string) {
const userOrgs = await this._organizationRepository.getOrgsByUserId(userId);
const findOrgToDelete = userOrgs.find((orgUser) => orgUser.id === org.id);
if (!findOrgToDelete) {
throw new Error('User is not part of this organization');
}
// @ts-ignore
const myRole = org.users[0].role;
const userRole = findOrgToDelete.users[0].role;
const myLevel = myRole === 'USER' ? 0 : myRole === 'ADMIN' ? 1 : 2;
const userLevel = userRole === 'USER' ? 0 : userRole === 'ADMIN' ? 1 : 2;
if (myLevel < userLevel) {
throw new Error('You do not have permission to delete this user');
}
return this._organizationRepository.deleteTeamMember(org.id, userId);
}
disableOrEnableNonSuperAdminUsers(orgId: string, disable: boolean) {
return this._organizationRepository.disableOrEnableNonSuperAdminUsers(
orgId,View on GitHub (pinned to 0f1647f749)
Solutions
- Refresh the member list and confirm the user is currently in this org before deleting
- Make the delete flow idempotent — treat 'not a member' as success
- Verify you're passing the correct userId (not an inviteId or orgUserId)
Example fix
// before
await deleteTeamMember(org, userId);
// after
const members = await listMembers(org.id);
if (members.some((m) => m.userId === userId)) {
await deleteTeamMember(org, userId);
} Defensive patterns
Strategy: validation
Validate before calling
const members = await listMembers(org.id); if (!members.some((m) => m.userId === userId)) return; // nothing to delete
Type guard
const isMemberOf = (userOrgs: {id: string}[], orgId: string): boolean => userOrgs.some((o) => o.id === orgId); Try / catch
try { await deleteTeamMember(org, userId); } catch (e) { if (/not part of this organization/.test(e.message)) return; // idempotent no-op throw e; } Prevention
- Refresh member state before delete actions
- Treat removal as idempotent to survive double-clicks and stale UI
When it happens
Trigger: Calling deleteTeamMember with a userId that never joined, already left, or belongs to a different org; stale UI showing a removed member; double-delete from concurrent requests.
Common situations: Member list is stale after a prior removal; admin removes the same user in two tabs; userId mismatch (e.g. passing invite id or the wrong user's id); eventual-consistency lag between removal and list refresh.
Related errors
- 'The organization plan does not include team members'
- No Postiz account found for this email
- Multiple accounts exist for this email (different login prov
- User is already a member of this organization
- Could not add the user to the organization
AI-assisted analysis of gitroomhq/postiz-app@0f1647f749 (2026-08-27).
Data as JSON: /api/errors/38f4ded8deee3476.
Report an issue: GitHub.