{"record":{"id":"b57ce0b0e3497386","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-b57ce0","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/users/getUsernameSuggestion.ts","lineNumber":20,"sourceCode":"import { Meteor } from 'meteor/meteor';\n\nimport { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\nimport { generateUsernameSuggestion } from '../../lib/users/getUsernameSuggestion';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tgetUsernameSuggestion(): Promise<string | undefined>;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync getUsernameSuggestion() {\n\t\tmethodDeprecationLogger.method('getUsernameSuggestion', '9.0.0', '/v1/users.getUsernameSuggestion');\n\t\tconst user = await Meteor.userAsync();\n\n\t\tif (!user) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'getUsernameSuggestion',\n\t\t\t});\n\t\t}\n\n\t\treturn generateUsernameSuggestion(user);\n\t},\n});\n","sourceCodeStart":2,"sourceCodeEnd":28,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/users/getUsernameSuggestion.ts#L2-L28","documentation":"getUsernameSuggestion loads the current user via Meteor.userAsync() and throws error-invalid-user when it resolves null — no authenticated user on the connection. The suggestion is generated from the logged-in user's profile, so an anonymous call cannot proceed. Deprecated since 9.0.0; REST replacement is /v1/users.getUsernameSuggestion.","triggerScenarios":"Calling Meteor.callAsync('getUsernameSuggestion') before login completes, after logout, or with an expired resume token.","commonSituations":"Onboarding/registration UI calling the suggestion method on a session that was dropped; guest signup pages calling it before the account exists.","solutions":["Only call after authentication — gate on Meteor.userId()","Re-login and retry once when this specific code is returned","Use the REST endpoint /v1/users.getUsernameSuggestion with an auth token for server-side integrations"],"exampleFix":"// before\nMeteor.callAsync('getUsernameSuggestion');\n\n// after\nif (!Meteor.userId()) {\n\tthrow new Error('login required');\n}\nawait Meteor.callAsync('getUsernameSuggestion');","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n\tthrow new Error('login required');\n}\nawait Meteor.callAsync('getUsernameSuggestion');","typeGuard":null,"tryCatchPattern":"try {\n\tawait Meteor.callAsync('getUsernameSuggestion');\n} catch (err) {\n\tif ((err as { error?: string }).error === 'error-invalid-user') {\n\t\t// not logged in — re-authenticate before suggesting usernames\n\t}\n}","preventionTips":["Call suggestion only after login resolves (onboarding flows inside authenticated area)","Check Meteor.userId() in component guards before mounting suggestion UI","Use the REST replacement /v1/users.getUsernameSuggestion for integrations"],"tags":["meteor","ddp","authentication","username","deprecation"],"backgroundTag":"user-not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}