user847495
user847495

Reputation: 10171

How do I make my sessions last cross-subdomain in Node.js Express?

I want http://mydomain.com to be the same as http://www.mydomain.com

And all other subdomains.

I want sessions and cookies to hold!

Upvotes: 8

Views: 4290

Answers (1)

Michael Lorton
Michael Lorton

Reputation: 44436

Has nothing to do with Express. It's the settings on the cookie itself that matter. Set its domain to .mydomain.com and you should be fine.

EDIT: The OP wanted more details, so here are the examples from the code.

  connect.createServer(
      connect.cookieParser()
    , connect.session({ cookie: { domain : ".mydomain.com" }})
  );

and

 res.cookie('remember', 1, { domain : ".mydomain.com" });

should work.

Upvotes: 12

Related Questions