Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise: How to use remember_me cookie after user sign out?

I'm working on a Rails 4.2 Application and using devise gem for authentication.

For remember_me feature, devise generates a cookie remember_user_token which gets destroy after sign_out.

Is there a way such that Devise should not destroy remember_user_token ?

I tried to false the below config in the initializer

config.expire_all_remember_me_on_sign_out = false

But it didn't help.

I need that cookie after sign-out such that it will populate the login form.

Please help.

Thanks

like image 505
Ahmad hamza Avatar asked Nov 21 '22 13:11

Ahmad hamza


1 Answers

Coupling authentication with form pre-filling isn't necessarily a good idea. You can store the login in a cookie upon successful login. You can override the create method in your SessionsController, call super to call Devise::SessionsController#create and pass it a block. The block will be executed after a successful log in and will receive the user as a parameter.

class SessionsController < Devise::SessionsController
  def create
    super do |user|
      cookies[:login] = user.login
    end
  end
end
like image 72
Greg Navis Avatar answered Mar 08 '23 15:03

Greg Navis