Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting ActionDispatch::Request::Session::DisabledSessionError after upgrading to rails 7

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 ?

like image 561
Dev V Avatar asked Jun 11 '26 18:06

Dev V


2 Answers

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

like image 198
trazillian Avatar answered Jun 13 '26 15:06

trazillian


Adding code below to config/initializers/devise.rb works for me.

config.warden do |manager|
  manager.scope_defaults :user, store: false
end
like image 45
Doble U Avatar answered Jun 13 '26 14:06

Doble U



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!