Zhinkk
Zhinkk

Reputation: 347

Hapijs cookie not setting

I read Hapijs's guide on cookies and tried to implement it. In my main index.js file I put the configuration as suggested:

server.state('data', {
    ttl: null,
    isSecure: true,
    isHttpOnly: true,
    encoding: 'base64json',
    clearInvalid: false,
    strictHeader: true
});

And then in my route I set the cookie "data" with some data to test it, like this:

{
    method: 'POST',
    path: '/create',
    handler: function (request, reply) {
        reply('hello').state('data', { firstVisit: true });
    }
}

When I check under cookies in the chrome debug tool, it doesn't show the cookie. What's strange is that it does reply with hello and it doesn't output any errors either. Does anybody know what I'm doing wrong?

Thanks!

Upvotes: 0

Views: 1441

Answers (1)

Zhinkk
Zhinkk

Reputation: 347

@devinivy from https://gitter.im/hapijs/hapi explained it:

isSecure tells the browser not to honor the cookie if there isn't a secured connection.

So the solution is as simple as making isSecure to false while not on HTTPS (at least for development purposes).

Upvotes: 2

Related Questions