带有Redis的Rails 5.2缓存存储不允许用户登录开发环境

时间:2018-10-10 14:27:57

标签: ruby-on-rails caching redis

我正在docker中运行rails 5.2应用程序,所有会话存储都运行良好,直到今天,我尝试使用Redis将session_storecookie_store更改为cache_store

在我的config / initializers / session_store.rb文件中,这是在开发中起作用的唯一选项(请注意cookie_store):

Rails.application.config.session_store :cookie_store,
                                           key: "_app_#{Rails.env}_session",
                                           domain: %w[.example.ru .example.io],
                                           expire_after: 24.hours,
                                           httponly: false

带有cache_store的配置在开发环境中不起作用,但在生产环境中起作用。

Rails.application.config.session_store :cache_store,
                                       key: "_app_#{Rails.env}_session",
                                       domain: %w[.example.ru .example.io],
                                       expire_after: 24.hours,
                                       httponly: false

在我的环境文件中,我有这个: config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }

.env文件中,我的redis网址为REDIS_URL=redis://0.0.0.0:6379/0

控制台中没有错误日志。知道为什么cache_store在开发环境中不起作用吗?

顺便说一句,我正在使用Devise gem进行身份验证。

使用服务器日志更新

使用cookie_store

时进行记录
web_1        | Started POST "/api/v1/auth" for 172.23.0.1 at 2018-10-10 15:21:12 +0000
web_1        | Cannot render console from 172.23.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
web_1        |    (1.0ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
web_1        |   ↳ /usr/local/bundle/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
web_1        | Processing by API::V1::AuthenticationController#create as HTML
web_1        |   Parameters: {"email"=>"user1@yandex.ru", "password"=>"[FILTERED]", "authentication"=>{"email"=>"user1@yandex.ru", "password"=>"[FILTERED]"}}
web_1        |   User Load (3.1ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", "user1@yandex.ru"], ["LIMIT", 1]]
web_1        |   ↳ app/controllers/api/v1/authentication_controller.rb:15
web_1        |    (0.3ms)  BEGIN
web_1        |   ↳ app/controllers/api/v1/authentication_controller.rb:19
web_1        |   User Update (1.9ms)  UPDATE "users" SET "current_sign_in_at" = $1, "last_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "users"."id" = $5  [["current_sign_in_at", "2018-10-10 15:21:14.709422"], ["last_sign_in_at", "2018-10-10 14:05:32.458533"], ["sign_in_count", 15], ["updated_at", "2018-10-10 15:21:14.716641"], ["id", 106]]
web_1        |   ↳ app/controllers/api/v1/authentication_controller.rb:19
web_1        |    (1.5ms)  COMMIT
web_1        |   ↳ app/controllers/api/v1/authentication_controller.rb:19
web_1        | [active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.15ms)
web_1        | Completed 200 OK in 615ms (Views: 165.5ms | ActiveRecord: 16.7ms)
web_1        | 
web_1        | 
web_1        | Started GET "/dashboard" for 172.23.0.1 at 2018-10-10 15:21:14 +0000
web_1        | Cannot render console from 172.23.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
web_1        | Processing by UsersController#show as HTML

使用cache_store时进行登录(这不会重定向到仪表板,它停留在同一页面上,只是重新提供登录页面)。

web_1        | Started POST "/api/v1/auth" for 172.23.0.1 at 2018-10-10 15:29:43 +0000
web_1        | Cannot render console from 172.23.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
web_1        | Processing by API::V1::AuthenticationController#create as HTML
web_1        |   Parameters: {"email"=>"user1@yandex.ru", "password"=>"[FILTERED]", "authentication"=>{"email"=>"user1@yandex.ru", "password"=>"[FILTERED]"}}
web_1        |   User Load (1.6ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", "user1@yandex.ru"], ["LIMIT", 1]]
web_1        |   ↳ app/controllers/api/v1/authentication_controller.rb:15
web_1        |    (0.4ms)  BEGIN
web_1        |   ↳ app/controllers/api/v1/authentication_controller.rb:19
web_1        |   User Update (3.2ms)  UPDATE "users" SET "current_sign_in_at" = $1, "last_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "users"."id" = $5  [["current_sign_in_at", "2018-10-10 15:29:44.123755"], ["last_sign_in_at", "2018-10-10 15:21:14.709422"], ["sign_in_count", 16], ["updated_at", "2018-10-10 15:29:44.132142"], ["id", 106]]
web_1        |   ↳ app/controllers/api/v1/authentication_controller.rb:19
web_1        |    (1.6ms)  COMMIT
web_1        |   ↳ app/controllers/api/v1/authentication_controller.rb:19
web_1        | [active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.17ms)
web_1        | Completed 200 OK in 489ms (Views: 199.9ms | ActiveRecord: 16.1ms)
web_1        | 
web_1        | 
web_1        | Started GET "/dashboard" for 172.23.0.1 at 2018-10-10 15:29:44 +0000
web_1        | Cannot render console from 172.23.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
web_1        | Processing by UsersController#show as HTML
web_1        | Redirected to http://localhost:3000/login
web_1        | Filter chain halted as :authenticate_user! rendered or redirected
web_1        | Completed 302 Found in 4ms (ActiveRecord: 0.0ms)
web_1        | 
web_1        | 
web_1        | Started GET "/login" for 172.23.0.1 at 2018-10-10 15:29:44 +0000
web_1        | Cannot render console from 172.23.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
web_1        | Processing by HomeController#login as HTML
web_1        |   Rendering home/login.html.haml within layouts/application
web_1        |   Rendered home/login.html.haml within layouts/application (5.0ms)
web_1        | Completed 200 OK in 760ms (Views: 739.1ms | ActiveRecord: 0.0ms)

通过更新日志,我注意到了不同之处,cache_store日志出现此错误-Filter chain halted as :authenticate_user! rendered or redirected必须是问题。 目前正在研究可能的解决方法。

0 个答案:

没有答案