{"record":{"id":"4deedb48d9090041","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-4deedb","errorCode":"error-invalid-user","errorMessage":"Invalid User","messagePattern":"Invalid User","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/bridges/webdav/methods/getWebdavFilePreview.ts","lineNumber":22,"sourceCode":"import { Meteor } from 'meteor/meteor';\nimport { createClient } from 'webdav';\n\nimport { settings } from '../../../settings';\nimport { getWebdavCredentials } from '../lib/getWebdavCredentials';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tgetWebdavFilePreview(accountId: IWebdavAccount['_id'], path: string): { success: true; data: ArrayBuffer } | undefined;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync getWebdavFilePreview(accountId, path) {\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: 'getWebdavFilePreview',\n\t\t\t});\n\t\t}\n\n\t\tif (!settings.get('Webdav_Integration_Enabled') || !settings.get('Accounts_OAuth_Nextcloud_URL')) {\n\t\t\tthrow new Meteor.Error('error-not-allowed', 'WebDAV Integration Not Allowed', {\n\t\t\t\tmethod: 'getWebdavFilePreview',\n\t\t\t});\n\t\t}\n\n\t\tconst account = await WebdavAccounts.findOneByIdAndUserId(accountId, userId, {});\n\t\tif (!account) {\n\t\t\tthrow new Meteor.Error('error-invalid-account', 'Invalid WebDAV Account', {\n\t\t\t\tmethod: 'getWebdavFilePreview',\n\t\t\t});\n\t\t}\n\n\t\ttry {","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/bridges/webdav/methods/getWebdavFilePreview.ts#L4-L40","documentation":"First guard in getWebdavFilePreview: Meteor.userId() returned falsy, so the DDP method call arrived on a connection without a valid authenticated user. Nothing WebDAV-specific has run yet; the method refuses to proceed for anonymous callers.","triggerScenarios":"Invoking the method from a logged-out session, with an expired or invalidated login token, or from server-side code that runs outside a user connection.","commonSituations":"Login token expired while the tab sat idle and the call races the re-login; code executed in a server-side job or test fixture that calls the method without a user context.","solutions":["Ensure the client is logged in (Meteor.userId() is set) before invoking the method","Re-login or wait for the resume token to be validated, then retry","If called from server code, invoke the underlying logic directly with an explicit userId instead of going through the method"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const userId = Meteor.userId();\nif (!userId) {\n  // route to login, or wait for the resume token before calling\n  throw new Error('login required');\n}\nconst preview = await Meteor.callAsync('getWebdavFilePreview', accountId, path);","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('getWebdavFilePreview', accountId, path);\n} catch (e: any) {\n  if (e?.error === 'error-invalid-user') {\n    // session expired: re-authenticate, then re-run the action\n  }\n}","preventionTips":["Gate WebDAV UI actions on an authenticated-account reactive check (Meteor.user()) so logged-out users never see them","Handle token-expiry flows (redirect to login) before method calls, not after"],"tags":["authentication","meteor-methods","webdav"],"backgroundTag":"user-not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}