Getting ActionDispatch::Request::Session::DisabledSessionError after upgrading to rails 7
Asked Answered
S

2

6

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 ?

Sosthina answered 10/10, 2022 at 19:21 Comment(0)
B
10

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

Boating answered 10/10, 2022 at 19:49 Comment(2)
I tried but it doesn't work in my case.Sosthina
As someone else wrote in the Github issue you mentioned, for me it was enough to simply remove :timeoutable from devise: github.com/waiting-for-dev/devise-jwt/issues/…Lemmon
A
3

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

config.warden do |manager|
  manager.scope_defaults :user, store: false
end
Ancestress answered 19/3 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.