{"record":{"id":"cb49b30b9c8f2b04","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-cb49b3","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/messages/updateMessage.ts","lineNumber":85,"sourceCode":"\t\tlet currentTsDiff = 0;\n\t\tlet msgTs;\n\n\t\tif (originalMessage.ts instanceof Date || Match.test(originalMessage.ts, Number)) {\n\t\t\tmsgTs = moment(originalMessage.ts);\n\t\t}\n\t\tif (msgTs) {\n\t\t\tcurrentTsDiff = moment().diff(msgTs, 'minutes');\n\t\t}\n\t\tif (currentTsDiff >= blockEditInMinutes) {\n\t\t\tthrow new Meteor.Error('error-message-editing-blocked', 'Message editing is blocked', {\n\t\t\t\tmethod: 'updateMessage',\n\t\t\t});\n\t\t}\n\t}\n\n\tconst user = await Users.findOneById(uid);\n\tif (!user) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'updateMessage' });\n\t}\n\tawait canSendMessageAsync(message.rid, { uid: user._id, username: user.username ?? undefined, ...user });\n\n\t// It is possible to have an empty array as the attachments property, so ensure both things exist\n\tif (originalMessage.attachments && originalMessage.attachments.length > 0 && originalMessage.attachments[0].description !== undefined) {\n\t\toriginalMessage.attachments[0].description = message.msg;\n\t\tmessage.attachments = originalMessage.attachments;\n\t\tmessage.msg = originalMessage.msg;\n\t}\n\n\tmessage.u = originalMessage.u;\n\n\treturn updateMessage(message, user, originalMessage, previewUrls);\n}\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/messages/updateMessage.ts#L67-L103","documentation":"updateMessage resolved the DDP connection's user id but Users.findOneById(uid) returned null — the user document no longer exists. The authenticated session points at a deleted (or missing) account, so the edit cannot proceed. This signals account/session inconsistency rather than a bad request.","triggerScenarios":"The user was deleted (admin purge, deletion workflow) while their DDP session or login token was still valid; the user record removed directly from the database; data inconsistency after a partial import or restore.","commonSituations":"Admin deletes a user whose client is still connected; automated cleanup purges accounts with live sessions; staging environments copied without the users collection.","solutions":["Log the affected client out and re-authenticate — a fresh session resolves to a valid identity or fails cleanly at login","Verify the account still exists via Admin > Users or the users.info REST endpoint for that uid","If deletion is intended, invalidate that user's sessions/tokens on deletion; if accidental, restore the account from backup"],"exampleFix":"// before\nawait Meteor.callAsync('updateMessage', payload); // throws for a deleted user's session\n\n// after\ntry {\n  await Meteor.callAsync('updateMessage', payload);\n} catch (e) {\n  if (isMeteorErrorCode(e, 'error-invalid-user')) {\n    await Meteor.logout(); // drop the stale session and send the user to login\n  }\n}","handlingStrategy":"try-catch","validationCode":"const me = await fetch('/api/v1/me', { headers: authHeaders() });\nif (me.status === 401 || me.status === 400) {\n  forceRelogin(); // session points at a missing/invalid user\n}","typeGuard":"const isInvalidUserError = (e: unknown): e is Meteor.Error =>\n  typeof e === 'object' && e !== null && (e as { error?: string }).error === 'error-invalid-user';","tryCatchPattern":"try {\n  await Meteor.callAsync('updateMessage', payload);\n} catch (e) {\n  if (isInvalidUserError(e) && Meteor.userId()) {\n    // session exists but the user document is gone — only recovery is re-login\n    await Meteor.logout();\n    redirectToLogin();\n    return;\n  }\n  throw e;\n}","preventionTips":["Invalidate sessions and tokens when deleting users so stale sessions fail cleanly","Treat error-invalid-user with a live session as a signal of account deletion, not a bug to retry","Monitor error-invalid-user spikes after user-purge maintenance"],"tags":["rocket-chat","meteor","user-management","session","data-consistency"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}