Rails 5.2 Cache Store с Redis не позволяет пользователю войти в среду разработки - PullRequest
0 голосов
/ 10 октября 2018

Я запускаю приложение rails 5.2 в докере, до сегодняшнего дня все хорошо работало с хранилищем сессий, я пытался изменить session_store с cookie_store на cache_store, используя Redis.

В моем файле 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

В моих файлах env у меня есть это: config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }

В файле .env мой URL-адрес redis равен REDIS_URL=redis://0.0.0.0:6379/0

И ошибки нетвойдите в консоль.Есть идеи, почему cache_store не работает в среде разработки?

И, кстати, я использую гем Devise для аутентификации.

Обновление с журналами сервера

Журнал прииспользование 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 Это должно быть проблемой.В настоящее время исследуются возможные способы исправить это.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...