{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/878","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/878/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/878/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/878/events","html_url":"https://github.com/strongloop/loopback/issues/878","id":50308419,"number":878,"title":"loopback.getCurrentContext() seems to return null when MySQL is used","user":{"login":"diasalvatore","id":796246,"avatar_url":"https://avatars.githubusercontent.com/u/796246?v=3","gravatar_id":"","url":"https://api.github.com/users/diasalvatore","html_url":"https://github.com/diasalvatore","followers_url":"https://api.github.com/users/diasalvatore/followers","following_url":"https://api.github.com/users/diasalvatore/following{/other_user}","gists_url":"https://api.github.com/users/diasalvatore/gists{/gist_id}","starred_url":"https://api.github.com/users/diasalvatore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diasalvatore/subscriptions","organizations_url":"https://api.github.com/users/diasalvatore/orgs","repos_url":"https://api.github.com/users/diasalvatore/repos","events_url":"https://api.github.com/users/diasalvatore/events{/privacy}","received_events_url":"https://api.github.com/users/diasalvatore/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/%23tob","name":"#tob","color":"666666"},{"url":"https://api.github.com/repos/strongloop/loopback/labels/bug","name":"bug","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":42,"created_at":"2014-11-27T16:35:44Z","updated_at":"2016-01-10T05:46:39Z","closed_at":null,"body":"As in https://github.com/strongloop/loopback/issues/569 I was trying to set currentUser in context in order to retrieve it after in requests.\r\n\r\n      app.use(loopback.token()); // this calls getCurrentContext\r\n      app.use(loopback.context()); // the context is started here\r\n\r\n      app.use(function (req, res, next) {\r\n        if (!req.accessToken) return next();\r\n        \r\n        app.models.User.findById(req.accessToken.userId, function(err, user) {\r\n          if (err)   return next(err);\r\n          if (!user) return next(new Error('No user with this access token was found.'));\r\n          res.locals.currentUser = user;\r\n\r\n          var loopbackContext = loopback.getCurrentContext();\r\n          if (loopbackContext) loopbackContext.set('currentUser', user);\r\n          next();\r\n        });\r\n      });\r\n\r\nthe problem is that `loopback.getCurrentContext()` returns `null` so it will not be set.\r\nWhy does this happen?"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/170316599","html_url":"https://github.com/strongloop/loopback/issues/878#issuecomment-170316599","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/878","id":170316599,"user":{"login":"tamilvendhank","id":625057,"avatar_url":"https://avatars.githubusercontent.com/u/625057?v=3","gravatar_id":"","url":"https://api.github.com/users/tamilvendhank","html_url":"https://github.com/tamilvendhank","followers_url":"https://api.github.com/users/tamilvendhank/followers","following_url":"https://api.github.com/users/tamilvendhank/following{/other_user}","gists_url":"https://api.github.com/users/tamilvendhank/gists{/gist_id}","starred_url":"https://api.github.com/users/tamilvendhank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tamilvendhank/subscriptions","organizations_url":"https://api.github.com/users/tamilvendhank/orgs","repos_url":"https://api.github.com/users/tamilvendhank/repos","events_url":"https://api.github.com/users/tamilvendhank/events{/privacy}","received_events_url":"https://api.github.com/users/tamilvendhank/received_events","type":"User","site_admin":false},"created_at":"2016-01-10T05:46:39Z","updated_at":"2016-01-10T05:46:39Z","body":"Same for me. Its not happening always. For one request, context is available. For the next, its not available. Same cycle repeats. I am using postgres connector."}}