diff --git a/lib/potassium/assets/config/initializers/session_store.rb b/lib/potassium/assets/config/initializers/session_store.rb new file mode 100644 index 00000000..c8c58839 --- /dev/null +++ b/lib/potassium/assets/config/initializers/session_store.rb @@ -0,0 +1,20 @@ +# https://github.com/redis-store/redis-store/issues/358#issuecomment-1537920008 +class RedisClient::Config + alias original_initialize initialize + + def initialize(**kwargs) + # remove not supported kwargs + original_initialize( + **kwargs.except(:raw, :serializer, :marshalling, :namespace, :scheme) + ) + end +end + +Rails.application.config.session_store :redis_store, { + servers: [{ + url: ENV['REDIS_URL'] + }], + expire_after: 3.days, + key: '_app_session', + secure: Rails.env.production? +} diff --git a/lib/potassium/recipes/redis.rb b/lib/potassium/recipes/redis.rb index 67289e14..6d8919ca 100644 --- a/lib/potassium/recipes/redis.rb +++ b/lib/potassium/recipes/redis.rb @@ -3,6 +3,7 @@ def create add_redis add_docker_compose_redis_config set_redis_dot_env + add_session_store_config end def install @@ -48,4 +49,9 @@ def set_redis_dot_env TEXT ) end + + def add_session_store_config + copy_file("../assets/config/initializers/session_store.rb", + "config/initializers/session_store.rb", force: true) + end end diff --git a/spec/features/redis_spec.rb b/spec/features/redis_spec.rb index b35e9a9d..3ad4b96b 100644 --- a/spec/features/redis_spec.rb +++ b/spec/features/redis_spec.rb @@ -34,5 +34,10 @@ expect(compose_content[:services]).to include(:redis) end + + it 'copies session store config' do + content = IO.read("#{project_path}/config/initializers/session_store.rb") + expect(content).to include("RedisClient::Config") + end end end