Set Cookie Domain

443 views
Skip to first unread message

Ryan

unread,
Nov 5, 2013, 9:46:40 PM11/5/13
to sai...@googlegroups.com
Hello,

I am new to Sails and Node/Express in general but really like it so far. One thing I would like to do is share a session across subdomains.

How can I set the cookie domain to something like domain: '.mysite.com'?

I tried doing that in config/session.js but didn't work.

Thanks for any help on this or a push in the right direction.

voltron

unread,
Nov 6, 2013, 12:15:34 AM11/6/13
to sai...@googlegroups.com
Hi Ryan,

Try this:
// config/session.js

cookie: { domain:'.yourdomain.com'},

Ryan

unread,
Nov 6, 2013, 9:05:03 PM11/6/13
to sai...@googlegroups.com
Yes, that was it.
Thanks!

Ryan

unread,
Nov 9, 2013, 7:53:31 PM11/9/13
to sai...@googlegroups.com
That worked in the fact that I see the cookie domain in Chrome dev tools is ".mysite.dev" for both http://mysite.dev and http://api.mysite.dev but the session value is different between both. If the session secrets are the same for both sails apps, shouldn't the session value be identical?

Anyway, when I try to send a socket request in app.js:

var api_url = 'http://api.mysite.dev';

 // dummy request to the server, retrieves cookie. using jQuery, you can use whatever
    $.get(api_url, function() {

      socket.request(api_url + '/user', function (response) {
        // Here's what the server responded with
        console.log(response);
      });
    });

I get the following error:

Could not parse: No session data returned, and an error was encountered saving session data for the first time: undefined SyntaxError {} sails.io.js:141
Uncaught Error: Server response could not be parsed!
No session data returned, and an error was encountered saving session data for the first time: undefined

This worked fine before adding cookie: {domain: '.mysite.dev'} to session.js.

Maybe I'm missing something simple but haven't found the fix yet.
Reply all
Reply to author
Forward
0 new messages