{"record":{"id":"8d8eb02c13b007ca","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-8d8eb0","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/auth/refreshOAuthService.ts","lineNumber":22,"sourceCode":"import { hasPermissionAsync } from '../../lib/authorization/hasPermission';\nimport { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\nimport { refreshLoginServices } from '../../lib/refreshLoginServices';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\trefreshOAuthService(): Promise<void>;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync refreshOAuthService() {\n\t\tmethodDeprecationLogger.method('refreshOAuthService', '9.0.0', '/v1/settings.refreshOAuthServices');\n\n\t\tconst userId = Meteor.userId();\n\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'refreshOAuthService',\n\t\t\t});\n\t\t}\n\n\t\tif ((await hasPermissionAsync(userId, 'add-oauth-service')) !== true) {\n\t\t\tthrow new Meteor.Error('error-action-not-allowed', 'Refresh OAuth Services is not allowed', {\n\t\t\t\tmethod: 'refreshOAuthService',\n\t\t\t\taction: 'Refreshing_OAuth_Services',\n\t\t\t});\n\t\t}\n\n\t\tawait refreshLoginServices();\n\t},\n});\n","sourceCodeStart":4,"sourceCodeEnd":37,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/auth/refreshOAuthService.ts#L4-L37","documentation":"The deprecated refreshOAuthService method throws 'error-invalid-user' when Meteor.userId() returns null, i.e. the DDP connection carries no authenticated user. The refresh of OAuth login services is an admin action and always requires a caller. Deprecated since 9.0.0 in favor of /v1/settings.refreshOAuthServices.","triggerScenarios":"Calling refreshOAuthService while logged out or after the resume token expired or was invalidated.","commonSituations":"Long-lived admin page with a stale session; post-restart token invalidation; automation invoking the method anonymously.","solutions":["Log in with a valid session before calling refreshOAuthService","Migrate to /v1/settings.refreshOAuthServices with an authenticated request","Handle session expiry centrally (re-login then retry once)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const userId = Meteor.userId();\nif (!userId) {\n  // re-authenticate before refreshing OAuth services\n}\nawait Meteor.callAsync('refreshOAuthService');","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('refreshOAuthService');\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-user') {\n    // session gone: re-login and retry\n  }\n}","preventionTips":["Require a live session for settings-mutating methods","Use /v1/settings.refreshOAuthServices for scripts with explicit auth"],"tags":["authentication","oauth","settings","meteor-methods","deprecated"],"backgroundTag":"not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}