{"action":"closed","issue":{"url":"https://api.github.com/repos/jalik/jalik-ufs/issues/21","labels_url":"https://api.github.com/repos/jalik/jalik-ufs/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/jalik/jalik-ufs/issues/21/comments","events_url":"https://api.github.com/repos/jalik/jalik-ufs/issues/21/events","html_url":"https://github.com/jalik/jalik-ufs/issues/21","id":112190311,"number":21,"title":"Meteor.userId can only be invoked in method calls.","user":{"login":"firewater","id":1868118,"avatar_url":"https://avatars.githubusercontent.com/u/1868118?v=3","gravatar_id":"","url":"https://api.github.com/users/firewater","html_url":"https://github.com/firewater","followers_url":"https://api.github.com/users/firewater/followers","following_url":"https://api.github.com/users/firewater/following{/other_user}","gists_url":"https://api.github.com/users/firewater/gists{/gist_id}","starred_url":"https://api.github.com/users/firewater/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/firewater/subscriptions","organizations_url":"https://api.github.com/users/firewater/orgs","repos_url":"https://api.github.com/users/firewater/repos","events_url":"https://api.github.com/users/firewater/events{/privacy}","received_events_url":"https://api.github.com/users/firewater/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-19T17:09:07Z","updated_at":"2015-10-20T19:48:32Z","closed_at":"2015-10-20T19:48:32Z","body":"Why can I not use Meteor.userId in collection.js ?\r\n\r\n\r\n**Error Message**\r\n\r\nW20151019-12:35:48.616(-4)? (STDERR) Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.\r\nW20151019-12:35:48.618(-4)? (STDERR)     at AccountsServer.userId (accounts_server.js:80:13)\r\nW20151019-12:35:48.618(-4)? (STDERR)     at Object.Meteor.userId (accounts_common.js:222:19)\r\n```W20151019-12:35:48.618(-4)? (STDERR)     at [object Object].UploadFS.store.Local.onRead (packages/me_mypack/collections.js:22:1)```\r\nW20151019-12:35:48.618(-4)? (STDERR)     at Object.path [as handle] (packages/jalik_ufs/ufs-server.js:156:1)\r\nW20151019-12:35:48.618(-4)? (STDERR)     at next (/Users/me/.meteor/packages/webapp/.1.2.2.v8ezdl++os+web.browser+web.cordova/npm/node_modules/connect/lib/proto.js:190:15)\r\nW20151019-12:35:48.619(-4)? (STDERR)     at Function.app.handle (/Users/me/.meteor/packages/webapp/.1.2.2.v8ezdl++os+web.browser+web.cordova/npm/node_modules/connect/lib/proto.js:198:3)\r\nW20151019-12:35:48.619(-4)? (STDERR)     at Object.fn [as handle] (/Users/me/.meteor/packages/webapp/.1.2.2.v8ezdl++os+web.browser+web.cordova/npm/node_modules/connect/lib/proto.js:74:14)\r\nW20151019-12:35:48.619(-4)? (STDERR)     at next (/Users/me/.meteor/packages/webapp/.1.2.2.v8ezdl++os+web.browser+web.cordova/npm/node_modules/connect/lib/proto.js:190:15)\r\nW20151019-12:35:48.619(-4)? (STDERR)     at Object.WebAppInternals.staticFilesMiddleware (packages/webapp/packages/webapp.js:370:1)\r\nW20151019-12:35:48.619(-4)? (STDERR)     at packages/webapp/packages/webapp.js:633:1\r\n\r\n\r\n\r\n**My package.js includes this line:**\r\n\r\n`api.add_files(\"collections.js\");`\r\n\r\n\r\n\r\n**collections.js (available on client & server)**\r\n\r\n```javascript\r\n/////////////////////////////////////\r\n// Define server & client collections.\r\n/////////////////////////////////////\r\n\r\n//mypack_std_out = new Mongo.Collection(\"mypack_std_out\");\r\n//mypack_std_err = new Mongo.Collection(\"mypack_std_err\");\r\nmypack_log = new Mongo.Collection(\"mypack_log\");\r\nmypack_jobs = new Mongo.Collection(\"mypack_jobs\");\r\nmypack_uploads = new Mongo.Collection(\"mypack_uploads\");\r\n\r\n// Uploaded files are stored here.\r\nmypack_uploads_store = new UploadFS.store.Local({\r\n\tcollection: mypack_uploads,\r\n\tname: 'mypack_uploads',\r\n\tpath: '~/mypack_uploads',\r\n\r\n\t// Called before reading file to check if we can return it.\r\n\tonRead: function (fileId, request, response) {\r\n\t\tvar doc = mypack_uploads.findOne(fileId);\r\n\t\tif (doc) {\r\n\t\t\t// User must own file to download it.\r\n\t\t\tif (doc.userId !== Meteor.userId()) {\r\n\t\t\t\tthrow new Meteor.Error(403, 'this file is private');\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tthrow new Meteor.Error(404, 'file not found');\r\n\t\t}\r\n\t},\r\n\r\n\t// Called when file has been uploaded.\r\n\tonFinishUpload: function (file) {\r\n\t\tconsole.log(file.name + ' has been uploaded');\r\n\t}\r\n});\r\n```"}}