Prevent session creation on rails 3.2.2 for RESTful api

不打扰是莪最后的温柔 提交于 2019-12-03 11:22:17

My problem here was with Warden inside Devise. I had to "tell" Warden not to store the user in the session after the user is authenticated.

resource = warden.authenticate!(:scope => resource_name, :store => !(request.format.xml? || request.format.json?))

Hope that helps whoever sees this thread.

Altonymous
resource = warden.authenticate!(:scope => resource_name, :store => is_navigational_format?)

in theory if you don't use it, it is not loaded now. up until rails 2.3.8, you could do:

# application_controller.rb
session :off, :if => :sessionless_request?

protected

def sessionless_request?(request)
  request.format == :xml || request.format == :json
end 

now you can do the same with this gem https://github.com/kares/session_off

You should use "devise :timeoutable" in your model and use config.timeout_in = 0 in config/initializers/devise.rb

Restart your server!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!