How do I keep the user signed in after they update their password using Devise? [duplicate]
Asked Answered
H

1

5

Whenever a user updates their password, it signs the user out and asks them to sign in again. This is my action

users_controller.rb
  def update
    @user = User.find(params[:id])
    if @user.update user_params
      sign_in @user, bypass: true # for some reason Devise signs the user out
      redirect_to @user

http://www.rubydoc.info/github/plataformatec/devise/Devise/Controllers/SignInOut#sign_in-instance_method

I tried sign_in @user, also, but that didn't work. I tried it without sign_in but that didn't work either. I saw this answer, but it doesn't help: Devise is logging out users after a password change. Updating the user without the password is working OK. (There is some code not shown.)

Devise 3.4.1.

Hokeypokey answered 23/5, 2015 at 21:56 Comment(0)
H
7

I had to add a 'scope`. This worked.

sign_in :user, @user, bypass: true # for some reason Devise signs the user out

See answer here: https://mcmap.net/q/263684/-devise-logging-out-automatically-after-password-change

Hokeypokey answered 23/5, 2015 at 22:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.