Skip to content

Instantly share code, notes, and snippets.

@amitpatelx
Created March 23, 2016 11:17
Show Gist options
  • Save amitpatelx/cc17c3a4abb48e133a90 to your computer and use it in GitHub Desktop.
Save amitpatelx/cc17c3a4abb48e133a90 to your computer and use it in GitHub Desktop.
How to share session between two Rails 4 applications?
# Use a different cache store in production.
# Configure this in both applications
elasticache = Dalli::ElastiCache.new('amit.patel.cfg.usw2.cache.amazonaws.com:11211')
config.cache_store = :dalli_store, elasticache.servers
# secret_key_base must be same for both applications
development:
secret_key_base: c85ef952bfeb14117a3d55c249fa5e582e5c6327fa56f227e6dbb88b4be780ba2aef9e20f58c3f65e0faf282a49a802aefa29d2aae3e36d1a4ffc7e625a644d5
test:
secret_key_base: 29f526a44fdd6f5596da9cb46ee4823da7ffaf9893a7c8e34f126dd9865bdaf0d65cb04381faf7d56544a86e688d1aa7704ceb23a65560585cca266946b877c2
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
# key and domain config must be same for both applications
Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 30.minutes, key: '_shared_session_key', domain: ".example.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment