{"record":{"id":"a0b4af0172576ee4","repo":"RocketChat/Rocket.Chat","slug":"failed-to-create-user","errorCode":null,"errorMessage":"Failed to create user","messagePattern":"Failed to create user","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/saml/lib/SAML.ts","lineNumber":202,"sourceCode":"\t\t\t\tif (i18n.languages?.includes(userObject.language)) {\n\t\t\t\t\tnewUser.language = userObject.language;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// only set skipAuthServiceDefaultRoles if SAML is providing its own roles\n\t\t\t// otherwise, leave it as false to fallback to generic auth service default roles\n\t\t\t// from Accounts_Registration_AuthenticationServices_Default_Roles\n\t\t\tconst skipAuthServiceDefaultRoles = roleNamesOrIds.length > 0;\n\t\t\tconst userId = await Accounts.insertUserDoc({ skipAuthServiceDefaultRoles, skipNewUserRolesSetting: true }, newUser);\n\t\t\tuser = await Users.findOneById(userId);\n\n\t\t\tif (user && userObject.channels && channelsAttributeUpdate !== true) {\n\t\t\t\tawait SAML.subscribeToSAMLChannels(userObject.channels, user);\n\t\t\t}\n\t\t}\n\n\t\tif (!user) {\n\t\t\tthrow new Error('Failed to create user');\n\t\t}\n\t\t// creating the token and adding to the user\n\t\tconst stampedToken = Accounts._generateStampedLoginToken();\n\t\tawait Users.addPersonalAccessTokenToUser({\n\t\t\tuserId: user._id,\n\t\t\tloginTokenObject: stampedToken as unknown as IPersonalAccessToken,\n\t\t});\n\n\t\tconst updateData: Record<string, any> = {\n\t\t\t'services.saml.provider': userObject.samlLogin.provider,\n\t\t\t'services.saml.idp': userObject.samlLogin.idp,\n\t\t\t'services.saml.idpSession': userObject.samlLogin.idpSession,\n\t\t\t'services.saml.nameID': userObject.samlLogin.nameID,\n\t\t};\n\n\t\t// If the user was not found through the customIdentifier property, then update it's value\n\t\tif (customIdentifierMatch === false && customIdentifierAttributeName) {\n\t\t\tupdateData[`services.saml.${customIdentifierAttributeName}`] = userObject.attributeList.get(customIdentifierAttributeName);","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/2a7de457074cbb4d4373fbd9a4e5bea292c9c764/apps/meteor/server/lib/saml/lib/SAML.ts#L184-L220","documentation":"Error \"Failed to create user\" thrown in RocketChat/Rocket.Chat.","triggerScenarios":"Thrown during SAML user provisioning when the user insert fails and no user id is returned.","commonSituations":"See trigger scenarios.","solutions":["Check server logs for the underlying user-creation failure (duplicate username/email, validation, or database error) and fix the conflicting data or SAML attribute mapping."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2a7de457074cbb4d4373fbd9a4e5bea292c9c764","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}