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.
Asked
Active
Viewed 611 times
2

Adam Young
- 1,321
- 4
- 20
- 36
-
ok and both aps are sharing the same db with users in it ? – Simon Franzen Mar 20 '18 at 13:46
-
Have you read https://stackoverflow.com/questions/29314817/share-session-between-two-rails4-applications?answertab=oldest#tab-top ? – Simon Franzen Mar 20 '18 at 13:47
-
yes. both are sharing the db – Adam Young Mar 20 '18 at 13:53
1 Answers
-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
-
-
@AdamYoung Follow the link in my answer. I think you will find there what you need. Sorry, I have to go now. Tell me if it worked or come back to you later this week. – Simon Franzen Mar 20 '18 at 14:10
-
how should I go about setting devise on my Rails 5 app so that current_user is accessible? – Adam Young Mar 20 '18 at 14:51