{"record":{"id":"fbadff9cb6ba64f0","repo":"RocketChat/Rocket.Chat","slug":"the-user-for-app-appid-is-not-registered","errorCode":null,"errorMessage":"The user for app ${appId} is not registered.","messagePattern":"The user for app (.+?) is not registered\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/app/apps/server/bridges/oauthApps.ts","lineNumber":21,"sourceCode":"import type { IAppServerOrchestrator } from '@rocket.chat/apps';\nimport { OAuthAppsBridge } from '@rocket.chat/apps/dist/server/bridges/OAuthAppsBridge';\nimport type { IOAuthApp, IOAuthAppParams } from '@rocket.chat/apps-engine/definition/accessors/IOAuthApp';\nimport type { IOAuthApps } from '@rocket.chat/core-typings';\nimport { OAuthApps, Users } from '@rocket.chat/models';\nimport { Random } from '@rocket.chat/random';\n\nexport class AppOAuthAppsBridge extends OAuthAppsBridge {\n\tconstructor(private readonly orch: IAppServerOrchestrator) {\n\t\tsuper();\n\t}\n\n\tprotected async create(oAuthApp: IOAuthAppParams, appId: string): Promise<string | null> {\n\t\tthis.orch.debugLog(`The App ${appId} is creating a new OAuth app.`);\n\t\tconst { clientId, clientSecret } = oAuthApp;\n\t\tconst botUser = await Users.findOne({ appId });\n\n\t\tif (!botUser) {\n\t\t\tthrow new Error(`The user for app ${appId} is not registered.`);\n\t\t}\n\n\t\tconst { _id, username } = botUser;\n\n\t\treturn (\n\t\t\tawait OAuthApps.insertOne({\n\t\t\t\t...oAuthApp,\n\t\t\t\t_id: randomUUID(),\n\t\t\t\tappId,\n\t\t\t\tclientId: clientId ?? Random.id(),\n\t\t\t\tclientSecret: clientSecret ?? Random.secret(),\n\t\t\t\t_createdAt: new Date(),\n\t\t\t\t_createdBy: {\n\t\t\t\t\t_id,\n\t\t\t\t\tusername,\n\t\t\t\t},\n\t\t\t} as unknown as IOAuthApps)\n\t\t).insertedId;","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/app/apps/server/bridges/oauthApps.ts#L3-L39","documentation":"Thrown by AppOAuthAppsBridge.create when no user document exists in the Users collection with the given appId. Rocket.Chat stores an App's bot identity as a user record tagged with appId; the OAuth app is then attributed to that bot user via _createdBy. Without the bot user the bridge cannot populate the audit fields and refuses to insert a dangling OAuth app.","triggerScenarios":"An App calls the OAuth apps accessor's create method before its own installation lifecycle has provisioned the bot user, or after the bot user was deleted (e.g. the App was uninstalled but a leftover code path still runs, or the App is running in a degraded state after a failed install). Also possible if appId was passed incorrectly and does not match the user record's appId field.","commonSituations":"Calling create during the App's constructor or onAppInitialize before the orchestrator has registered the bot user; reinstalling an App whose previous bot user was manually purged from the DB; multi-instance setups where the user write has not yet replicated; passing the wrong appId after an App was re-installed under a new id.","solutions":["Ensure create is only called after the App's IPostAppInstall or later lifecycle hook where the bot user is guaranteed to exist.","Verify the bot user with `Users.findOne({ appId })` (or the users accessor) before calling create, and surface a clear error.","If the bot user was deleted, reinstall the App so the installation lifecycle recreates it.","Confirm the appId you pass matches the id under which the App was installed."],"exampleFix":"// before\n// called inside onPreInstall\nawait oauthApps.create(params, appId);\n\n// after\n// called inside onPostInstall or later\nconst bot = await users.getAppUser(appId);\nif (!bot) throw new Error('Bot user not provisioned yet');\nawait oauthApps.create(params, appId);","handlingStrategy":"validation","validationCode":"const botUser = await users.getAppUser(appId); // or Users.findOne({ appId })\nif (!botUser) {\n  throw new Error(`Cannot create OAuth app: bot user for ${appId} is not provisioned. Reinstall the App or move the call to onPostInstall.`);\n}\nawait oauthApps.create(params, appId);","typeGuard":null,"tryCatchPattern":"try {\n  return await oauthApps.create(params, appId);\n} catch (e) {\n  if (e instanceof Error && /not registered/.test(e.message)) {\n    // bot user missing — defer or reinstall\n    this.app.getLogger().error('OAuth app create failed: bot user missing. Reinstall the App.');\n    throw e;\n  }\n  throw e;\n}","preventionTips":["Only call create from onPostInstall or later lifecycle hooks where the bot user exists.","Track the bot user id after install and reuse it instead of re-querying by appId at every call.","If the App was uninstalled/reinstalled, ensure the previous bot user was cleaned up to avoid appId collisions."],"tags":["apps-engine","oauth-apps-bridge","bot-user","lifecycle","installation"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}