{"action":"created","issue":{"url":"https://api.github.com/repos/dwyl/hapi-auth-jwt2/issues/274","repository_url":"https://api.github.com/repos/dwyl/hapi-auth-jwt2","labels_url":"https://api.github.com/repos/dwyl/hapi-auth-jwt2/issues/274/labels{/name}","comments_url":"https://api.github.com/repos/dwyl/hapi-auth-jwt2/issues/274/comments","events_url":"https://api.github.com/repos/dwyl/hapi-auth-jwt2/issues/274/events","html_url":"https://github.com/dwyl/hapi-auth-jwt2/issues/274","id":317482358,"number":274,"title":"Not working with file uploads(multipart formdata)","user":{"login":"hussainb","id":4962633,"avatar_url":"https://avatars0.githubusercontent.com/u/4962633?v=4","gravatar_id":"","url":"https://api.github.com/users/hussainb","html_url":"https://github.com/hussainb","followers_url":"https://api.github.com/users/hussainb/followers","following_url":"https://api.github.com/users/hussainb/following{/other_user}","gists_url":"https://api.github.com/users/hussainb/gists{/gist_id}","starred_url":"https://api.github.com/users/hussainb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hussainb/subscriptions","organizations_url":"https://api.github.com/users/hussainb/orgs","repos_url":"https://api.github.com/users/hussainb/repos","events_url":"https://api.github.com/users/hussainb/events{/privacy}","received_events_url":"https://api.github.com/users/hussainb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-25T05:22:47Z","updated_at":"2018-04-28T04:36:09Z","closed_at":null,"author_association":"NONE","body":"\r\n**Registering the plugin:**\r\n\r\n```\r\n    await server.register(require('hapi-auth-jwt2'));\r\n    server.auth.strategy('jwt', 'jwt',\r\n        {\r\n            key: tokenSecret,\r\n            validate: async (decoded, request) => {\r\n                return { isValid: true }\r\n            },\r\n            verifyOptions: { algorithms: ['HS256'] }\r\n        });\r\n\r\n    await server.register({\r\n        plugin: require('hapi-routes'),\r\n        options: {\r\n            dir: `${__dirname}/app/routes/*`,\r\n        },\r\n    });\r\n\r\n```\r\n\r\n\r\n**Route Configuration:**\r\n\r\n```\r\nexport { }\r\n\r\nimport uploadCtrl from '../controllers/uploadCtrl';\r\n\r\nconst routes = [{\r\n    method: 'POST',\r\n    path: '/upload',\r\n    options: {\r\n        payload: {\r\n            output: 'stream',\r\n            allow: 'multipart/form-data', // important\r\n            maxBytes: 100000000\r\n        },\r\n        auth: 'jwt'\r\n    },\r\n    handler: uploadCtrl\r\n}];\r\n\r\nexports.routes = (server: any) => server.route(routes);\r\n\r\n```\r\n\r\n**POST response with a file:**\r\n\r\n![image](https://user-images.githubusercontent.com/4962633/39227297-84cea7e4-4875-11e8-8f3a-fbdfedbecb5b.png)\r\n\r\n\r\n**POST response without a file (expected similar response for POST with the file):**\r\n\r\n![image](https://user-images.githubusercontent.com/4962633/39227328-af8b2a52-4875-11e8-989d-d69e4e0d9313.png)\r\n\r\n**Dummy authorization header used for the above:**\r\n\r\n![image](https://user-images.githubusercontent.com/4962633/39227375-e8377cac-4875-11e8-904f-d6a8b7ff66ef.png)\r\n\r\n\r\n**No errors/warnings/info generated by Hapi in the console below for both the cases:**\r\n\r\n![image](https://user-images.githubusercontent.com/4962633/39227465-5f1da6a2-4876-11e8-8f01-b12dd6e9df28.png)\r\n\r\n\r\n\r\nI am not able to figure out if I am missing something or if there is some other issue.\r\n"},"comment":{"url":"https://api.github.com/repos/dwyl/hapi-auth-jwt2/issues/comments/385139742","html_url":"https://github.com/dwyl/hapi-auth-jwt2/issues/274#issuecomment-385139742","issue_url":"https://api.github.com/repos/dwyl/hapi-auth-jwt2/issues/274","id":385139742,"user":{"login":"hussainb","id":4962633,"avatar_url":"https://avatars0.githubusercontent.com/u/4962633?v=4","gravatar_id":"","url":"https://api.github.com/users/hussainb","html_url":"https://github.com/hussainb","followers_url":"https://api.github.com/users/hussainb/followers","following_url":"https://api.github.com/users/hussainb/following{/other_user}","gists_url":"https://api.github.com/users/hussainb/gists{/gist_id}","starred_url":"https://api.github.com/users/hussainb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hussainb/subscriptions","organizations_url":"https://api.github.com/users/hussainb/orgs","repos_url":"https://api.github.com/users/hussainb/repos","events_url":"https://api.github.com/users/hussainb/events{/privacy}","received_events_url":"https://api.github.com/users/hussainb/received_events","type":"User","site_admin":false},"created_at":"2018-04-28T04:36:08Z","updated_at":"2018-04-28T04:36:08Z","author_association":"NONE","body":"@stefan-c \r\nYes the server was running when I sent the first request.\r\nI am just toggling the file checkbox in postman and the response varies.\r\n\r\nMy code is similar to yours.\r\nBelow is the simplified version which doesn't work for me while doing a file post.\r\n\r\n**server.ts**\r\n\r\n```\r\nimport * as Hapi from 'hapi';\r\nimport * as Boom from 'boom';\r\nimport * as path from 'path'\r\nimport * as fs from 'fs';\r\nimport * as loki from 'lokijs';\r\n\r\nimport { tokenSecret } from './app/controllers/authCtrl';\r\n\r\n// Create a server with a host and port\r\nconst server = new Hapi.Server({\r\n    host: 'localhost',\r\n    port: 8000\r\n});\r\n\r\nconst registerPlugs = async () => {\r\n\r\n    await server.register(require('hapi-auth-jwt2'));\r\n    server.auth.strategy('jwt', 'jwt',\r\n        {\r\n            key: tokenSecret,\r\n            validate: async (decoded, request) => {\r\n                return { isValid: true }\r\n            },\r\n            verifyOptions: { algorithms: ['HS256'] }\r\n        });\r\n\r\n    await server.register({\r\n        plugin: require('hapi-routes'),\r\n        options: {\r\n            dir: `${__dirname}/app/routes/*`,\r\n        },\r\n    });\r\n\r\n    // Add the route\r\n    server.route({\r\n        method: 'GET',\r\n        path: '/hello',\r\n        handler: function (request, h) {\r\n            return 'hello world';\r\n        },\r\n        options: { auth: 'jwt' }\r\n    });\r\n\r\n    console.log(\"plugins registered\")\r\n}\r\n\r\n\r\n\r\n\r\n// Start the server\r\nasync function start() {\r\n    await registerPlugs();\r\n\r\n    try {\r\n        await server.start();\r\n    }\r\n    catch (err) {\r\n        console.log(err);\r\n        process.exit(1);\r\n    }\r\n\r\n    console.log('Server running at:', server.info.uri);\r\n};\r\n\r\nprocess.on('unhandledRejection', (err) => {\r\n    console.log(err);\r\n    process.exit(1);\r\n});\r\n\r\nstart();\r\n```\r\n\r\nand since I am using the plugin `hapi-routes` \r\n\r\n**upload.ts**\r\n\r\n```\r\nexport { }\r\n\r\nimport uploadCtrl from '../controllers/uploadCtrl';\r\n\r\nconst routes = [{\r\n    method: 'POST',\r\n    path: '/upload',\r\n    options: {\r\n        payload: {\r\n            output: 'stream',\r\n            allow: 'multipart/form-data', // important\r\n            maxBytes: 100000000\r\n        },\r\n        auth: 'jwt'\r\n    },\r\n    // handler: uploadCtrl\r\n    handler: () => 'ok'\r\n}];\r\n\r\nexports.routes = (server: any) => server.route(routes);\r\n```\r\n\r\n"}}
{"actor":{"display_login":"hussainb"}}