diff --git a/packages/server/src/sdk/users/utils.ts b/packages/server/src/sdk/users/utils.ts index a3982fd45b..7f7f0b4809 100644 --- a/packages/server/src/sdk/users/utils.ts +++ b/packages/server/src/sdk/users/utils.ts @@ -75,14 +75,19 @@ export async function syncGlobalUsers() { toWrite.push(combined) } } + let foundEmails: string[] = [] for (let data of metadata) { if (!data._id) { continue } + const alreadyExisting = data.email && foundEmails.indexOf(data.email) !== -1 const globalId = getGlobalIDFromUserMetadataID(data._id) - if (!users.find(user => user._id === globalId)) { + if (!users.find(user => user._id === globalId) || alreadyExisting) { toWrite.push({ ...data, _deleted: true }) } + if (data.email) { + foundEmails.push(data.email) + } } await db.bulkDocs(toWrite) } diff --git a/packages/types/src/documents/app/user.ts b/packages/types/src/documents/app/user.ts index b5f31ca349..4defd4a414 100644 --- a/packages/types/src/documents/app/user.ts +++ b/packages/types/src/documents/app/user.ts @@ -2,4 +2,5 @@ import { Document } from "../document" export interface UserMetadata extends Document { roleId: string + email?: string }