Devise logging out automatically after password change

后端 未结 9 1815
离开以前
离开以前 2020-12-07 19:53

In Devise, if I change user\'s password and after it gets updated in the db, the site immediately logs out the user. I don\'t want this behavior - how do i do that. please h

相关标签:
9条回答
  • 2020-12-07 20:14

    I had the same problem and the following code seems to work for me.

    Assume that the passwords controller is set for a singleton route. Also, assume that the authenticated model is an Account. With that, you have the following:

    def update
      if current_account.update_with_password(params[:account])
        sign_in(current_account, :bypass => true)
        flash[:notice] = 'Password updated.'
        redirect_to account_path
      else
        render :action => :show
      end
    end
    

    The key ingredient is the sign_in method call which seeks to re-sign-in the account, but bypasses the warden callbacks and stores the account into the session.

    0 讨论(0)
  • 2020-12-07 20:19

    Use the registerable module, which will give you both sign up and edit user features

    https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password

    0 讨论(0)
  • 2020-12-07 20:22

    Please refer to this answer here, I tried all the above answers. It din't work for not adding the scope. https://stackoverflow.com/a/30418266/4973585

    This doesn't work - sign_in @user, bypass: true

    This works - sign_in :user, @user, bypass: true

    0 讨论(0)
  • 2020-12-07 20:24

    You can simply set sign_in_after_reset_password in your devise.rb

    config.sign_in_after_reset_password = true
    
    0 讨论(0)
  • 2020-12-07 20:25

    Use this code to avoid sign out.

    sign_in(current_user, :bypass => true)
    
    0 讨论(0)
  • 2020-12-07 20:28

    For some reasons, current_user is not equal to @user although current_user.id is equal to @user.id. So I have to use sign_in(@user, :bypass => true).

    0 讨论(0)
提交回复
热议问题