2

We have a setup in a way that currently some pages are being served by a Rails 4 app and a Rails 5 app. All the authentication logic resides in the Rails 4 app and we are using Devise for authentication. The session_store.rb on the Rails 4 app looks like this Rails.application.config.session_store :cookie_store, key: '_app_store'. I want to have the current_user accessible in the Rails 5 app as well. Note: Both the apps are under the same domain. Also how should I go about setting devise on my Rails 5 app so that current_user is accessible.

Adam Young
  • 1,321
  • 4
  • 20
  • 36

1 Answers1

-1

First allow cookie to apply for all of your subdomains:

Rails.application.config.session_store :cookie_store, key: '_app_store', domain: :all

When the browser accesses a website, the website tells the browser to set a cookie. When this happens, it specifies the cookie name, value, domain, and path.

:domain => :all makes a dot in front of the cookie domain (which is whatever host your browser has browsed to), so the cookie applies to all subdomains.

Another good thread about this topic can be found here: https://stackoverflow.com/a/4065929/1625253

Simon Franzen
  • 2,628
  • 25
  • 34