diff --git a/.changeset/perfect-sloths-marry.md b/.changeset/perfect-sloths-marry.md new file mode 100644 index 0000000000000..06711274be016 --- /dev/null +++ b/.changeset/perfect-sloths-marry.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +fixes an issue with OAuth not syncing user roles on their first login diff --git a/apps/meteor/app/custom-oauth/server/custom_oauth_server.js b/apps/meteor/app/custom-oauth/server/custom_oauth_server.js index c45f3619c8aac..bfed645e146de 100644 --- a/apps/meteor/app/custom-oauth/server/custom_oauth_server.js +++ b/apps/meteor/app/custom-oauth/server/custom_oauth_server.js @@ -445,7 +445,11 @@ Accounts.updateOrCreateUserFromExternalService = async function (...args /* serv const [serviceName, serviceData] = args; - const user = updateOrCreateUserFromExternalService.apply(this, args); + const user = await updateOrCreateUserFromExternalService.apply(this, args); + if (!user.userId) { + return undefined; + } + const fullUser = await Users.findOneById(user.userId); if (settings.get('LDAP_Update_Data_On_OAuth_Login')) { await LDAP.loginAuthenticatedUserRequest(fullUser.username);