{"action":"created","issue":{"url":"https://api.github.com/repos/express-validator/express-validator/issues/621","repository_url":"https://api.github.com/repos/express-validator/express-validator","labels_url":"https://api.github.com/repos/express-validator/express-validator/issues/621/labels{/name}","comments_url":"https://api.github.com/repos/express-validator/express-validator/issues/621/comments","events_url":"https://api.github.com/repos/express-validator/express-validator/issues/621/events","html_url":"https://github.com/express-validator/express-validator/issues/621","id":349664796,"node_id":"MDU6SXNzdWUzNDk2NjQ3OTY=","number":621,"title":"access express.Response in CustomValidator","user":{"login":"timothyallan","id":1995135,"node_id":"MDQ6VXNlcjE5OTUxMzU=","avatar_url":"https://avatars0.githubusercontent.com/u/1995135?v=4","gravatar_id":"","url":"https://api.github.com/users/timothyallan","html_url":"https://github.com/timothyallan","followers_url":"https://api.github.com/users/timothyallan/followers","following_url":"https://api.github.com/users/timothyallan/following{/other_user}","gists_url":"https://api.github.com/users/timothyallan/gists{/gist_id}","starred_url":"https://api.github.com/users/timothyallan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timothyallan/subscriptions","organizations_url":"https://api.github.com/users/timothyallan/orgs","repos_url":"https://api.github.com/users/timothyallan/repos","events_url":"https://api.github.com/users/timothyallan/events{/privacy}","received_events_url":"https://api.github.com/users/timothyallan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-08-10T21:38:18Z","updated_at":"2018-08-13T02:47:32Z","closed_at":null,"author_association":"NONE","body":"Hi! I've checked the docs/workarounds, and I think I already know the answer, but here goes: I've got a middleware setup which does authentication, and populates `res.locals` with a user object after authentication. The next middleware in the chain is express-validator. \r\n\r\nI'm not able to access my user object in `res.locals` in a custom validator to validate user specific checks, as the custom validator only exposes the `req` object. Is there any current way to get access to the `res` object in a custom validator? \r\n\r\nI could always do something like store it in Redis, or somewhere else, but it's a 3rd party auth library and the less hacks the better.\r\n"},"comment":{"url":"https://api.github.com/repos/express-validator/express-validator/issues/comments/412395393","html_url":"https://github.com/express-validator/express-validator/issues/621#issuecomment-412395393","issue_url":"https://api.github.com/repos/express-validator/express-validator/issues/621","id":412395393,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMjM5NTM5Mw==","user":{"login":"gustavohenke","id":826553,"node_id":"MDQ6VXNlcjgyNjU1Mw==","avatar_url":"https://avatars2.githubusercontent.com/u/826553?v=4","gravatar_id":"","url":"https://api.github.com/users/gustavohenke","html_url":"https://github.com/gustavohenke","followers_url":"https://api.github.com/users/gustavohenke/followers","following_url":"https://api.github.com/users/gustavohenke/following{/other_user}","gists_url":"https://api.github.com/users/gustavohenke/gists{/gist_id}","starred_url":"https://api.github.com/users/gustavohenke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gustavohenke/subscriptions","organizations_url":"https://api.github.com/users/gustavohenke/orgs","repos_url":"https://api.github.com/users/gustavohenke/repos","events_url":"https://api.github.com/users/gustavohenke/events{/privacy}","received_events_url":"https://api.github.com/users/gustavohenke/received_events","type":"User","site_admin":false},"created_at":"2018-08-13T02:47:32Z","updated_at":"2018-08-13T02:47:32Z","author_association":"MEMBER","body":"Thanks for pointing me to the library.\r\nYou could just add your own middleware between express-validator and express-oauth-server:\r\n\r\n```js\r\napp.use(oauth.authorize());\r\napp.use((req, res, next) => {\r\n  req.locals.oauth = res.locals.oauth;\r\n});\r\n// routes, validations, etc\r\n```\r\n\r\nThis might work for others in the same situation, too.\r\n\r\nNavigating the response object down where the custom validators are invoked would be quite some work. In terms of API change, it would be non-breaking, so it's fine to have it.\r\n\r\nHowever, I'm happy to see PRs for this; I'm quite low on time for this kind of maintenance at the moment."}}
{"actor":{"display_login":"gustavohenke"}}