From a235562c82e34848793ae4f52ac58a3d12367c2b Mon Sep 17 00:00:00 2001 From: minottic Date: Wed, 5 Jun 2024 10:46:35 +0200 Subject: [PATCH] Avoids identities duplication when recreated in kc When user is recreated in KC, the backend sees a new externalId, which causes a new identity to be created, with a non updated attributes --- helm/configs/backend/login-callbacks.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/helm/configs/backend/login-callbacks.js b/helm/configs/backend/login-callbacks.js index 0684f9ce..4789554b 100644 --- a/helm/configs/backend/login-callbacks.js +++ b/helm/configs/backend/login-callbacks.js @@ -2,7 +2,12 @@ exports.accessGroupsToProfile = function (req, done) { - return function (err, user, identity, token) { + return async function (err, user, identity, token) { + await user.identities.destroyAll({and: [ + {provider: identity.provider}, + {id: {neq: identity.id}}, + {userId: user.id} + ]}); identity.updateAttributes({ "profile": { accessGroups: identity.profile._json.pgroups,