Jason Silberman
Jason Silberman

Reputation: 2491

Devise: Sharing sessions (user state) across subdomains

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

Upvotes: 3

Views: 1788

Answers (1)

Richard Peck
Richard Peck

Reputation: 76774

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

Upvotes: 3

Related Questions