9

I want to let the same user session span across:

  • site.com
  • sub1.site.com
  • sub2.site.com

I got this to work in production by setting SESSION_COOKIE_DOMAIN to ".site.com", but it doesn't work for me on localhost/dev servers. How do you get it to work for localhost sub-domains? When I change the SESSION_COOKIE_DOMAIN on the dev server to the production website domain or ".localhost", django auth logins completely stop working (I'm unable to ever login, no cookie is created on localhost).

outis
  • 75,655
  • 22
  • 151
  • 221
MikeN
  • 45,039
  • 49
  • 151
  • 227
  • I believe this is a duplicate, see this question: [http://stackoverflow.com/questions/1442017/subdomains-and-logins](http://stackoverflow.com/questions/1442017/subdomains-and-logins) – Michael Cheng Sep 18 '09 at 00:56
  • See "[Add subdomain to localhost URL](/q/19016553/90527)". – outis Aug 17 '22 at 20:28

1 Answers1

16

I think I got a workaround solution, but couldn't use localhost. I could only get it working for a test ".com" domain that maps to 127.0.0.1.

In my /etc/hosts file (on OSX:)

    127.0.0.1  test.com
    127.0.0.1  sub1.test.com
    127.0.0.1  sub2.test.com

Then on my development settings.py:

    SESSION_COOKIE_DOMAIN=".test.com"

I could not get this working with plain "localhost", it seemed I needed the ".com" string in there to get it working. So then I could login and have cross subdomain auth cookies using sub1.test.com:8000 and sub2.test.com:8000 in my browser.

MikeN
  • 45,039
  • 49
  • 151
  • 227