From b5666902addfccb948c5e7a8314c98456a0fcf38 Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Wed, 6 Sep 2023 21:25:35 +0530 Subject: [PATCH 1/2] fix: afterCreate callback missing roles info --- apps/meteor/app/authentication/server/startup/index.js | 4 ++++ apps/meteor/app/lib/server/functions/saveUser.js | 1 + 2 files changed, 5 insertions(+) diff --git a/apps/meteor/app/authentication/server/startup/index.js b/apps/meteor/app/authentication/server/startup/index.js index e3b97c1aae88..3c97f3efcaaf 100644 --- a/apps/meteor/app/authentication/server/startup/index.js +++ b/apps/meteor/app/authentication/server/startup/index.js @@ -269,6 +269,10 @@ const insertUserDocAsync = async function (options, user) { globalRoles.push(...user.globalRoles); } + if (options.roles) { + user.roles = [...new Set([...(user.roles || []), ...options.roles])]; + } + delete user.globalRoles; if (user.services && !user.services.password) { diff --git a/apps/meteor/app/lib/server/functions/saveUser.js b/apps/meteor/app/lib/server/functions/saveUser.js index f912626c833e..a9845e422c1b 100644 --- a/apps/meteor/app/lib/server/functions/saveUser.js +++ b/apps/meteor/app/lib/server/functions/saveUser.js @@ -279,6 +279,7 @@ const saveNewUser = async function (userData, sendPassword) { password: userData.password, joinDefaultChannels: userData.joinDefaultChannels, isGuest, + roles, }; if (userData.email) { createUser.email = userData.email; From e5747328b83f9d3a5d7e3213756c29207685f527 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Wed, 6 Sep 2023 08:40:39 -0600 Subject: [PATCH 2/2] callback being called (cherry picked from commit 8ef0b3852f73e83ea858823dfec1b1ccd3d6e947) --- apps/meteor/app/authentication/server/startup/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/app/authentication/server/startup/index.js b/apps/meteor/app/authentication/server/startup/index.js index 3c97f3efcaaf..a67b0fd03cc2 100644 --- a/apps/meteor/app/authentication/server/startup/index.js +++ b/apps/meteor/app/authentication/server/startup/index.js @@ -328,7 +328,7 @@ const insertUserDocAsync = async function (options, user) { await addUserRolesAsync(_id, roles); // Make user's roles to be present on callback - user = await Users.findOneById(_id, { projection: { username: 1, type: 1 } }); + user = await Users.findOneById(_id, { projection: { username: 1, type: 1, roles: 1 } }); if (user.username) { if (options.joinDefaultChannels !== false) {