Stop Devise from clearing session

前端 未结 4 1991
孤独总比滥情好
孤独总比滥情好 2020-12-01 12:47

It seems when a user logs out via standard Devise controllers, Devise destroys the entire session store, not just its own data. Is there any way to avoid this behavior? I ha

4条回答
  •  [愿得一人]
    2020-12-01 12:48

    In addition to Mattheus. The statement

    signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
    

    is perhaps the best general log out statement, considering the possibility of being signed in with multiple roles. If, for you case, your user is just signed in as one role, and you want to preserve the rest of the session on signout, the easiest way is to do:

    $ git clone git://github.com/plataformatec/devise.git
    $ cd devise
    $ git branch my_devise
    $ git checkout my_devise
    

    Open app/controllers/devise/sessions_controller.rb in your editor. In the method destroy, replace

    signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
    

    with

    signed_out = sign_out(resource_name)
    

    Save and exit editor and do

    $ git commit -am "remove only warden data from session on logout, preserve other data."
    

    In the Gemfile of your project, describe the dependency to devise like

    gem 'devise', :path => "[YOUR PATH]/devise", :branch => "my_devise"
    

提交回复
热议问题