outmoded / university

Community learning experiment
Other
371 stars 193 forks source link

Error: Request interface decoration already defined: cookieAuth #187

Closed Miguel-Herrero closed 8 years ago

Miguel-Herrero commented 8 years ago

I have followed the Assignments successfully (updating the code to use latest versions) until the one with hapi-auth-cookie. I cannot make it work, because when I start the server (npm start), this error appears:

node lib/start.js

/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/node_modules/hoek/lib/index.js:732
    throw new Error(msgs.join(' ') || 'Unknown error');
    ^

Error: Request interface decoration already defined: cookieAuth
    at Object.exports.contain.exports.reachTemplate.exports.assert.condition [as assert] (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/node_modules/hoek/lib/index.js:732:11)
    at internals.Generator.decorate (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/lib/request.js:54:10)
    at module.exports.internals.Plugin.internals.Plugin.register.internals.Plugin.decorate (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/lib/plugin.js:365:37)
    at Object.internals.implementation.server.ext [as cookie] (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi-auth-cookie/lib/index.js:125:12)
    at internals.Auth.strategy (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/lib/auth.js:51:43)
    at module.exports.internals.Plugin.internals.Plugin.register.internals.Plugin._applyChild (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/lib/plugin.js:587:19)
    at Object.auth.default.scheme.strategy (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/lib/plugin.js:72:18)
    at /Users/Miguel/Sites/git/Miguel-Herrero/university/lib/auth-cookie.js:31:21
    at /Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/lib/server.js:357:18
    at iterate (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/node_modules/items/lib/index.js:36:13)
    at Object.exports.serial (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/node_modules/items/lib/index.js:39:9)
    at internals.Server.start.internals.Server.initialize.internals.Server._start.internals.Server.stop._invoke.internals.Server._invoke.next [as _invoke] (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/lib/server.js:354:11)
    at /Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/lib/server.js:236:14
    at done (/Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/node_modules/items/lib/index.js:63:25)
    at /Users/Miguel/Sites/git/Miguel-Herrero/university/node_modules/hapi/node_modules/hoek/lib/index.js:850:22
    at nextTickCallbackWith0Args (node.js:452:9)

Theoretically I know what it means, but I don't know where I am redecorating the cookieAuth in my code.

I would be very thankful if anybody could review my fork and give me some advice as to where to look… Thank you in advance.

(Note: previous assignment successfully passed tests with 100 % coverage)

zoe-1 commented 8 years ago

Did the following: git checkout myAssignment7_i155 npm install npm start result below:

Error: Cannot find module 'boom'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (../Miguel-Herrero/university/lib/api/login.js:6:14)

You need to debug this yourself. Perhaps, you are rushing.
Slow down and build each piece of your application step by step.
At each step of building your application run tests and prove it works

D34THWINGS commented 8 years ago

How did you resolved this issue ?

zoe-1 commented 8 years ago

@D34THWINGS release of next assignment (assignment7 update to ES6) will illustrate how to do this. Worked on it some today and hope to finish in next day or two.

Usually, this relates to hapi-auth-cookie 's strategy being registered to the correct hapi server connection.
Assuming you are using Glue and you have multiple connections (tls and non-tls). Check that the plugin which registers the auth-cookie strategy is assigned to the correct connection (ex. tls) versus just the general server object with no connection specified.

Sample manifest

internals.manifest = {
    connections: [
        {
            host: 'localhost',
            port: 0,
            labels: ['web']
        },
        {
            host: 'localhost',
            port: 0,
            labels: ['web-tls'],
            tls: Config.tls
        }
    ],
    registrations: [
        {
            plugin: './auth-dev',
            options: {
                select: ['web-tls']
            }
        },
        {
            plugin: './cookie-auth',
            options: {
                select: ['web-tls']
            }
        },
        {
            plugin: 'hapi-auth-cookie',
        }

    ]
};

Assuming the above cookie-auth plugin has the: server.auth.strategy(name, scheme, [mode], [options]) logic inside it. The server object must be pointing to one of the server connections above. Otherwise, you get the below message: Error: Request interface decoration already defined: cookieAuth.

If you dropped the below configuration from the cookie-auth plugins options. It creates the error message.

options: {
     select: ['web-tls']
}

The above reflects how I usually create this error and trouble shoot it. Have not looked much at @Miguel-Herrero 's project for the reasons mentioned above.

D34THWINGS commented 8 years ago

@zoe-1 Thanks for your time and for the explanation, I was effectively registering the strategy on global server, switching it to a per connection registration worked perfectly !

zoe-1 commented 8 years ago

@D34THWINGS Glad it worked for you :)