RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-user
error-invalid-user
Error message
Invalid user
What it means
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.
Source
Thrown at apps/meteor/server/meteor-methods/users/getUsernameSuggestion.ts:20
import { Meteor } from 'meteor/meteor';
import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';
import { generateUsernameSuggestion } from '../../lib/users/getUsernameSuggestion';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
getUsernameSuggestion(): Promise<string | undefined>;
}
}
Meteor.methods<ServerMethods>({
async getUsernameSuggestion() {
methodDeprecationLogger.method('getUsernameSuggestion', '9.0.0', '/v1/users.getUsernameSuggestion');
const user = await Meteor.userAsync();
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'getUsernameSuggestion',
});
}
return generateUsernameSuggestion(user);
},
});
View on GitHub (pinned to b2c16d5842)
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
Example fix
// before
Meteor.callAsync('getUsernameSuggestion');
// after
if (!Meteor.userId()) {
throw new Error('login required');
}
await Meteor.callAsync('getUsernameSuggestion'); Defensive patterns
Strategy: validation
Validate before calling
if (!Meteor.userId()) {
throw new Error('login required');
}
await Meteor.callAsync('getUsernameSuggestion'); Try / catch
try {
await Meteor.callAsync('getUsernameSuggestion');
} catch (err) {
if ((err as { error?: string }).error === 'error-invalid-user') {
// not logged in — re-authenticate before suggesting usernames
}
} Prevention
- 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
When it happens
Trigger: Calling Meteor.callAsync('getUsernameSuggestion') before login completes, after logout, or with an expired resume token.
Common situations: Onboarding/registration UI calling the suggestion method on a session that was dropped; guest signup pages calling it before the account exists.
Understand the failure class
Background: error-invalid-user: "Invalid user" errors in Rocket.Chat — what they mean and how to fix them — this error's family across 2 libraries.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/b57ce0b0e3497386.
Report an issue: GitHub.