Skip to content

Commit bb2b4ec

Browse files
Allow model config to override sign_in_after_change_password (#5825)
The config exists at the model/resource class from the registerable module, but it was not being honored, instead we were directly relying on the main Devise config. Now this can be configured and honored per-model/resource class, as expected. This is similar to #5429 and `sign_in_after_reset_password` fix.
1 parent e5ffdc4 commit bb2b4ec

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### Unreleased
2+
3+
* enhancements
4+
* Allow resource class scopes to override the global configuration for `sign_in_after_change_password` behaviour. [#5824](https://github.com/heartcombo/devise/pull/5824)
5+
16
### 5.0.1 - 2026-02-13
27

38
* bug fixes

app/controllers/devise/registrations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,6 @@ def set_flash_message_for_update(resource, prev_unconfirmed_email)
163163
def sign_in_after_change_password?
164164
return true if account_update_params[:password].blank?
165165

166-
Devise.sign_in_after_change_password
166+
resource_class.sign_in_after_change_password
167167
end
168168
end

test/integration/registerable_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ def user_sign_up
187187
end
188188
end
189189

190+
test 'a signed in user should not be able to use the website after changing their password if resource_class.sign_in_after_change_password is false' do
191+
swap_model_config User, sign_in_after_change_password: false do
192+
sign_in_as_user
193+
get edit_user_registration_path
194+
195+
fill_in 'password', with: '1234567890'
196+
fill_in 'password confirmation', with: '1234567890'
197+
fill_in 'current password', with: '12345678'
198+
click_button 'Update'
199+
200+
assert_contain 'Your account has been updated successfully, but since your password was changed, you need to sign in again.'
201+
assert_equal new_user_session_path, @request.path
202+
assert_not warden.authenticated?(:user)
203+
end
204+
end
205+
190206
test 'a signed in user should be able to use the website after changing its email with config.sign_in_after_change_password is false' do
191207
swap Devise, sign_in_after_change_password: false do
192208
sign_in_as_user

0 commit comments

Comments
 (0)