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 have other irrelevant data that should be kept around.
session[:my_var] = "123"
Log out via devise…
puts session[:my_var]
# => nil
The
destroy¹ method ofSessionsControllercontains the following line:The
sign_out_all_scopes² method callswarden.logoutwithout any arguments, and thesign_out³ method callswarden.logout(scope).The documentation of the
logout⁴ method states:Conclusion:
sign_outshould preserve the session when given a specific scope. However, I don’t see any way to do that.sign_out_all_scopesis always called first, and will only returnfalseif it couldn’t log any user out.I recommend either posting a feature request on their issue tracker or developing your own authentication solution. Rails now provides
has_secure_password, and these days people seem to be going for the latter in order to avoid running into these problems.¹
Devise::SessionsController#destroy²
Devise::Controllers::Helpers#sign_out_all_scopes³
Devise::Controllers::Helpers#sign_out⁴
Warden::Proxy#logout