Home > Blockchain >  Getting ActionDispatch::Request::Session::DisabledSessionError after upgrading to rails 7
Getting ActionDispatch::Request::Session::DisabledSessionError after upgrading to rails 7

Time:10-12

I recently upgraded my application to rails 7 and now a bunch of my tests are failing with the below error.

ActionDispatch::Request::Session::DisabledSessionError: Your application has sessions disabled. To write to the session you must first configure a session store

I am suspecting this has something to do with devise. Below is the code that is causing issues.

def login_user(user)
  post "/api/v2/login", :params => { :username => user.username, :password => user.password }
  assert_response :success, response.body
  json = JSON.parse(response.body)
  {:authentication_token => json["user"]["authentication_token"]}
end

If I remove the line config.api_only = true from the application.rb file then the test cases pass without any hitch but I can't really remove that line due to other issues. Does anybody a proper solution for this issue ?

CodePudding user response:

I found a similar question: Rails 7 API only app requiring session store with Devise

where it's suggested to add following to your config/application.rb :

config.session_store :cookie_store, key: '_interslice_session'
    config.middleware.use ActionDispatch::Cookies
    config.middleware.use config.session_store, config.session_options

based on this issue on github

  • Related