1

I have an app set up with a main domain and multiple subdomains. I have devise up and working on the main domain, but when I enter subdomain.domain.com whatever session is currently on the domain is not recognized. I have seen and tried the answers found in SO posts (also this one) and blogs alike, but nothing seems to be working.

I am working with my config/initializers/session_store.rb file and have tried:

Bdc::Application.config.session_store :cookie_store, key: '_bdc_session', domain: lvh.me, tld_length: 2

I have tried the following permutations as well:

  • domain: :all
  • tld_length: '1'
  • No tld_length listed

None of these have worked. I am using Rails 4.2.5 and devise 4.0. Can anyone help me get to the point where I can have the same session persist from domain.com to subdomain1.domain.com, subdomain2.domain.com, etc.?

Community
  • 1
  • 1
Liz
  • 1,369
  • 2
  • 26
  • 61

1 Answers1

0

Change the config/initializers/session_store.rb

Bdc::Application.config.session_store :cookie_store, key: '_bdc_session', domain: .lvh.me, tld_length: 2
Pratap
  • 327
  • 2
  • 12
  • Unfortunately, for this I get an error when I try to start the server `session_store.rb:6: syntax error, unexpected '.' (SyntaxError) ... key: '_bdc_session', domain: .lvh.me, tld_length: 2 ... ^ ` – Liz Nov 16 '16 at 18:30
  • If I use quotes around `".lvh.me" the server starts, but it still does not recognize a session in my subdomain. – Liz Nov 16 '16 at 18:31
  • or try config.session_store :cookie_store, :key => '_domain_session', :domain => :all – Pratap Nov 17 '16 at 09:23
  • Actually, after using this for a bit, this caused [this](http://stackoverflow.com/questions/40667563/activerecordstatementinvalid-sqlite3ioexception-disk-i-o-error) error. Can you opine? – Liz Nov 18 '16 at 02:03
  • Also, the version you suggested made the devise not register sessions due to CSRF token authenticity issues... – Liz Nov 18 '16 at 02:33
  • What ended up working was `Bdc::Application.config.session_store :cookie_store, key: '_bdc_session', domain: ".domain.com"`, which didn't cause the funky error. – Liz Nov 19 '16 at 16:21