Per cookie share per subdomain

I have a blog subdomain that works well, however, signin is separated from all subdomains, and therefore, if a user signs in with his cookie, it is valid only on non-domain pages. How can I configure my application so that cookies are valid in all subdomains and normal pages?

I worked on this topic: Share session (cookies) between subdomains in Rails? but, unfortunately, without success. I even tried this long step-by-step intermediate approach, but without success.

I am using Rails 3.2.13.

Any help appreciated! :)

+6
source share
2 answers

All I had to do was specify the domain when creating the cookie, as mentioned earlier.

cookies[:remember_token] = { value: user.remember_token, domain: ".lvh.me" } 
+16
source

Put domain: all at the end of the line in config / session_store.rb

eg.

 YourApp::Application.config.session_store :encrypted_cookie_store, key: '_yourapp_session', domain: :all 

You may also need to change this setting in config / environment / production.rb

 config.action_dispatch.tld_length = 2 

If your domain is example.com , then your tld_length (top-level domain length) is 1 (which is the default value). example.com.au is 2, 127.0.0.1.xip.io is 5, etc.

+1
source

All Articles