{"action":"created","issue":{"url":"https://api.github.com/repos/hapijs/hapi/issues/3112","repository_url":"https://api.github.com/repos/hapijs/hapi","labels_url":"https://api.github.com/repos/hapijs/hapi/issues/3112/labels{/name}","comments_url":"https://api.github.com/repos/hapijs/hapi/issues/3112/comments","events_url":"https://api.github.com/repos/hapijs/hapi/issues/3112/events","html_url":"https://github.com/hapijs/hapi/issues/3112","id":146636700,"number":3112,"title":"how does one send data to the client outside of the handler in hapi?","user":{"login":"quixotic-ambition","id":9903191,"avatar_url":"https://avatars.githubusercontent.com/u/9903191?v=3","gravatar_id":"","url":"https://api.github.com/users/quixotic-ambition","html_url":"https://github.com/quixotic-ambition","followers_url":"https://api.github.com/users/quixotic-ambition/followers","following_url":"https://api.github.com/users/quixotic-ambition/following{/other_user}","gists_url":"https://api.github.com/users/quixotic-ambition/gists{/gist_id}","starred_url":"https://api.github.com/users/quixotic-ambition/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quixotic-ambition/subscriptions","organizations_url":"https://api.github.com/users/quixotic-ambition/orgs","repos_url":"https://api.github.com/users/quixotic-ambition/repos","events_url":"https://api.github.com/users/quixotic-ambition/events{/privacy}","received_events_url":"https://api.github.com/users/quixotic-ambition/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hapijs/hapi/labels/question","name":"question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":{"login":"Marsup","id":796194,"avatar_url":"https://avatars.githubusercontent.com/u/796194?v=3","gravatar_id":"","url":"https://api.github.com/users/Marsup","html_url":"https://github.com/Marsup","followers_url":"https://api.github.com/users/Marsup/followers","following_url":"https://api.github.com/users/Marsup/following{/other_user}","gists_url":"https://api.github.com/users/Marsup/gists{/gist_id}","starred_url":"https://api.github.com/users/Marsup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Marsup/subscriptions","organizations_url":"https://api.github.com/users/Marsup/orgs","repos_url":"https://api.github.com/users/Marsup/repos","events_url":"https://api.github.com/users/Marsup/events{/privacy}","received_events_url":"https://api.github.com/users/Marsup/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2016-04-07T14:04:25Z","updated_at":"2016-04-11T11:01:52Z","closed_at":null,"body":"const HapiMongoModels = require('hapi-mongo-models');\r\nconst Joi = require('joi');\r\nvar jWt = require('jsonwebtoken');\r\nvar fs=require('fs');\r\nvar Hapi = require('hapi');\r\n\r\nvar secret_key = fs.readFileSync('example.key');\r\n\r\n\r\nvar server = new Hapi.Server();\r\nserver.connection({port:8000});\r\n\r\n\r\n    const plugin = {\r\n        register: HapiMongoModels,\r\n        options: {\r\n            mongodb: {\r\n              url: 'mongodb://localhost:27017/jj_test',\r\n              options: {}\r\n            },\r\n            autoIndex: true,\r\n            models: {\r\n                Users:'./models/userList.js'\r\n            }\r\n        }\r\n    }\r\n\r\n\r\n    var validate = function (decoded, request, callback) {\r\n \r\n        var Users = request.server.plugins['hapi-mongo-models'].Users;\r\n        var filter={}\r\n        filter.username = decoded['0']['username'];\r\n        var obj;\r\n        Users.find(filter,(err, results) => {\r\n\r\n            if (err) {\r\n                console.log( err );\r\n                reply(err);\r\n                return;\r\n            }\r\n\r\n            obj=results;\r\n\r\n            if (obj)\r\n                return callback(null, true);\r\n            }\r\n            else\r\n            return callback(null, false);    \r\n         });           \r\n\r\n    };\r\n\r\n\r\nserver.register(require('hapi-auth-jwt2'), function (err) {\r\n\r\n    if(err){\r\n      console.log(err);\r\n    } \r\n\r\n    console.log(\"runnig jwt\");\r\n\r\n    server.auth.strategy('jwt', 'jwt',{ \r\n        key:secret_key,           \r\n        validateFunc: validate,             \r\n        verifyOptions:{algorithm:['HS256']}\r\n    });\r\n\r\n    server.auth.default('jwt');\r\n\r\n    server.register(plugin, (err) => {\r\n\r\n        if (err) {\r\n            console.log('Failed loading plugin');\r\n        }\r\n\r\n\r\n        console.log(\"hapi mongo models plugin registered\");\r\n\r\n\r\n        server.route({\r\n            method: 'GET',\r\n            path: '/',\r\n            config: {\r\n                auth:'jwt'\r\n\r\n            },\r\n            handler: function (request, reply) {\r\n                console.log(\"Entered handler\");\r\n               reply(\"token used\").header(\"Authorization\", request.headers.authorization);\r\n            }\r\n        });\r\n\r\n\r\n\r\n        server.route({\r\n            method: 'POST',\r\n            path: '/insert/{username}',\r\n            config: {\r\n                auth:false\r\n\r\n            },\r\n            handler: function (request, reply) {\r\n                console.log(\"Entered post handler\");\r\n                var Users = request.server.plugins['hapi-mongo-models'].Users;\r\n                var temp={};\r\n                temp.username=request.params.username;\r\n                Users.insertOne(temp,function(err,results){\r\n\r\n                    if (err) {\r\n                        console.log( err );\r\n                        reply(err);\r\n                        return;\r\n                    }\r\n\r\n                    console.log(\"inserted user\");\r\n                    reply(\"inserted\");\r\n                });\r\n            }\r\n \r\n       });\r\n    server.start(function () {\r\n        console.log('Server running at:', server.info.uri);\r\n    });\r\n\r\n    });\r\n\r\n});\r\n\r\n\r\n\r\n\r\n/* Firstly , I am not sure if I asked the right question but I will specifically tell you what I want to do.\r\nI want to reply the \"obj\" in my \"validate\" function to the path:'/' (GET) after I have verified the token in the same function. Everything i am referring to is in the code above.(In case that was not clear)\r\n\r\nThe rest of the code seems to be working fine . Also I went through another thread on this website where the person uses reply.hold somehow to reply outside the handler which i think could help me solve my issue . I could not figure out a way to use it in my program probably because of my lack of understanding of how it works.\r\n\r\nDesperately looking for help. Thank you.\r\n*/"},"comment":{"url":"https://api.github.com/repos/hapijs/hapi/issues/comments/208286122","html_url":"https://github.com/hapijs/hapi/issues/3112#issuecomment-208286122","issue_url":"https://api.github.com/repos/hapijs/hapi/issues/3112","id":208286122,"user":{"login":"quixotic-ambition","id":9903191,"avatar_url":"https://avatars.githubusercontent.com/u/9903191?v=3","gravatar_id":"","url":"https://api.github.com/users/quixotic-ambition","html_url":"https://github.com/quixotic-ambition","followers_url":"https://api.github.com/users/quixotic-ambition/followers","following_url":"https://api.github.com/users/quixotic-ambition/following{/other_user}","gists_url":"https://api.github.com/users/quixotic-ambition/gists{/gist_id}","starred_url":"https://api.github.com/users/quixotic-ambition/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quixotic-ambition/subscriptions","organizations_url":"https://api.github.com/users/quixotic-ambition/orgs","repos_url":"https://api.github.com/users/quixotic-ambition/repos","events_url":"https://api.github.com/users/quixotic-ambition/events{/privacy}","received_events_url":"https://api.github.com/users/quixotic-ambition/received_events","type":"User","site_admin":false},"created_at":"2016-04-11T11:01:52Z","updated_at":"2016-04-11T11:01:52Z","body":"@Marsup Updated the thread . sorry i did not do it earlier!  Also sorry for replying so late i will respond more promply from now on.\r\n"}}