0

I am new to NodeJs Development. I am using HapiJs framework. I have set cookie using following code:

        reply("hello").state('cookie_name', accessToken, {
          ttl: 365 * 24 * 60 * 60 * 1000, // expires a year from today
          encoding: 'none',
          isSecure: false,
          isHttpOnly: false,
          clearInvalid: false,
          strictHeader: true
        });

the above code is working perfectly and I am able to see the cookie being set in browser with the name cookie_name along with an extra cookie named io (which I guess is automatically set by socket.io node module I am using)

but when I am trying to get that cookie using following code

request.headers.cookie

It only shows one cookie (i.e io). its not showing me up the cookie with the name cookie_name. So, can anyone tell me what is the mistake am I making here. Am I passing incorrect values in options while setting cookie or do I need to retrive cookies using some other way.

Dimpal Singh
  • 157
  • 12

1 Answers1

0

In our Hapi application, we're using the hapi-auth-cookie plugin.

There is an example application here that shows its use quite well.

rotarydial
  • 2,181
  • 2
  • 23
  • 27
  • what is `password-should-be-32-characters` here and is it necessary to be of 32 characters. Also is `sid-example` the name of cookie? – Dimpal Singh Dec 14 '17 at 05:20
  • @DimpalSingh, for the password, they're just suggesting using one that's 32 characters *or longer* for security reasons. – rotarydial Dec 14 '17 at 05:59
  • Read the documentation at the top; don't just skip down to the code examples. It explains: "The 'cookie' scheme takes the following options: "cookie - the cookie name. Defaults to 'sid'."... – rotarydial Dec 14 '17 at 06:01
  • Thanks, Finally it worked. But I needed to update hapi version to 17.0.1. Only then it worked. Thanks a ton mate. – Dimpal Singh Dec 14 '17 at 17:19