Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate is running a second time and 500-ing hapi #89

Closed
excenter opened this issue Aug 8, 2016 · 1 comment
Closed

Generate is running a second time and 500-ing hapi #89

excenter opened this issue Aug 8, 2016 · 1 comment
Labels
Milestone

Comments

@excenter
Copy link

@excenter excenter commented Aug 8, 2016

possibly related to #54
For a restful hapi pipeline, with the conf below, after I generate a crumb and get it back as a cookie. When I submit a data request I get

Debug: internal, implementation, error 
    TypeError: Uncaught error: Cannot read property 'crumb' of null
    at generate (/Users/$ME/Developer/pipeline/node_modules/crumb/lib/index.js:159:34)

The index.js of the hapi server asks for this:

server.register(
        {
            register: require('crumb'),
            options: {
                restful: true
            }
        },
        (err) => {
            if (err) {
                throw err;
            }
        }
    );

and the restful requests are

const env = require("../../config/environment"),
    httpreq = require('request');
module.exports = [
    {
        method: 'GET',
        path: '/generate',
        config: {
          auth: false
        },
        handler: function (request, reply) {
            return reply(
                { crumb: request.server.plugins.crumb.generate(request, reply) }
            );
        }
    },
    {
        method: 'PUT',
        path: '/crumbed',
        handler: function (request, reply) {
            console.log('crumb put has happened')
            console.log(request);
            return reply('../../node_modules/crumb/lib/index.js');
                   // it says crumb route, meaning this? 
        }
    }
];

(fun fact, I never see 'crumb put has happened' when PUT-ing to /crumbed, the 500 previously mentioned hits first).

Is this a bug with the generate function, or have I just royally failed to configure crumb?

@stongo

This comment has been minimized.

Copy link
Contributor

@stongo stongo commented Aug 12, 2016

your PUT route should now just be a normal route protected by crumb (no need to reply with that index.js file)

make sure your request to the PUT route (or any PUT, POST, DELETE, PATCH route) contains the header X-CSRF-Token: {value-you-got-from-generate-route}

@stongo stongo closed this Aug 15, 2016
@stongo stongo added this to the 6.0.3 milestone Aug 15, 2016
@stongo stongo added the question label Aug 15, 2016
@Marsup Marsup added support and removed question labels Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.