【发布时间】:2023-04-10 14:15:01
【问题描述】:
很长一段时间以来出现了一些奇怪的行为。部署后(使用 capistarano),所有用户都需要重新登录!
自 Rails 4.x 以来在多个应用程序中发生......这里有一些版本:
- 导轨:4.2.5 / 4.2.6
- 设计:3.5.3 / 3.5.6 / 4.2.0
- Capistrano:3.4.0
- 红宝石:2.2.1 / 2.3.0
- Web 服务器:nginx
- 应用服务器:瘦 (1.6.4 / 1.7.0)
这真的很烦人,特别是因为零停机时间部署不再有意义,而且记住我根本不起作用
模型/用户
class User < ActiveRecord::Base
..
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable,
:validatable, :confirmable, :lockable, :timeoutable, :omniauthable, :invitable,
:omniauth_providers => CONFIG[:devise_provider]
..
end
初始化器/设计
Devise.setup do |config|
config.secret_key = 'xxx-key-xxx'
config.mailer_sender = CONFIG[:mail_system]
config.mailer = 'AccountMailer'
require 'devise/orm/active_record'
config.case_insensitive_keys = [:email]
config.strip_whitespace_keys = [:email]
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 10
config.invite_for = 0
config.reconfirmable = true
config.expire_all_remember_me_on_sign_out = true
config.password_length = CONFIG[:password_min_length]..CONFIG[:password_max_length]
config.timeout_in = 6.hours
config.reset_password_within = 6.hours
config.sign_out_via = :delete
config.omniauth :facebook, CONFIG[:facebook_id], CONFIG[:facebook_secret], {info_fields: 'email, first_name, last_name, gender', image_size: "large"}
config.omniauth :google_oauth2, CONFIG[:google_id], CONFIG[:google_secret], {
skip_jwt: true,
scope: "email, profile, plus.me",
# prompt: "select_account",
image_aspect_ratio: "square",
image_size: 200
}
end
大多数应用程序都在生产环境中运行,因此我在部署时不会接触数据库(迁移除外)。 也发生在没有 devise_invitable 的应用程序中,所以这也不会导致它。
.. 感谢您的帮助! ..
也发布为devise #4277
【问题讨论】:
-
您的
config/secrets.yml是如何配置的?虽然这不是发生这种情况的唯一方式,但如果您的生产密码在每次部署时发生更改,所有会话都会过期。 -
其中 2 个应用程序在 deploy.rb 中硬编码,因此无法更改 .. 但会再次检查
标签: ruby-on-rails-4 nginx devise thin capistrano3