3

I have my project set up using Rails 4.2, Ruby 2.2, and Devise 3.5.

I have an app with multiple sudomains and I would like a user's state (logged in/out) to be shared across those subdomains.

I have set my session store up like this:

config.session_store :cookie_store, :key => '_app_name_session', :domain => '.name.app', :tld_length => 2

However this does not seem to be doing anything as when I inspect the session in Chrome, it is called the _app_session, which is the incorrect session name so this makes me think that rails is ignoring these settings.

How can I setup Devise to work using sessions that will work with all of the different sub domains?

Thanks

Jason Silberman
  • 2,471
  • 6
  • 29
  • 47

1 Answers1

3

We use the following for our subdomains:

# config/initializers/session_store.rb
# Be sure to restart your server when you modify this file.

Rails.application.config.session_store :cookie_store, key: '_[[name]]_session', domain: :all # tld_length info here: http://stackoverflow.com/questions/10402777/share-session-cookies-between-subdomains-in-rails/15009883#15009883

You should try setting domain: :all and maybe removing tld_length from the hash

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • 2
    Thanks, so I got it to work by keeping the domain to '.name.app' but removing the tld_length from it. – Jason Silberman Jan 04 '16 at 22:25
  • 1
    @JasonSilberman Did you manage to share sessions between different apps under the same domain, using the same User table? I want to do the same with Devise. Any thoughts? – Sergio Gonzalez Nov 15 '17 at 21:22