-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DisabledSessionError when using authenticate_user! api only #5443
Comments
More context: Before Rails 7, the session passed to warden was a Hash. So even if the session was disabled, we were still able to write to the hash. Now, the session is an |
I understand that Devise relies heavily on warden etc which rely on sessions, or a fake version of it at least. Thus, we've circumvented this by creating this concern/module that we have included in the relevant Devise-related controllers in our app: module RackSessionFixController
extend ActiveSupport::Concern
class FakeRackSession < Hash
def enabled?
false
end
end
included do
before_action :set_fake_rack_session_for_devise
private
def set_fake_rack_session_for_devise
request.env['rack.session'] ||= FakeRackSession.new
end
end
end if the devise maintainers like it, we (AKA me or my team) can integrate this into Devise itself (E.g. allowing that logic to happen when API-mode is enabled) and expand the testsuite accordingly. @carlosantoniodasilva WDYT ? |
@morenocarullo i use |
@arpu you need to drop that module I wrote in my earlier comment and include it in the SessionControllers. If @carlosantoniodasilva or other maintainer can suggest their acceptance, I can for sure make it included in |
reference rails change rails/rails#42231 |
Thanks a lot for the help @morenocarullo. I am using this resolution while the issue is not resolved |
Any update on when this will be fixed? |
@connortorrell you can use the solution posted here. I'm waiting for maintainers to say they'll accept the PR -- before it stays there forever |
Did they accept the PR? |
@NfoCipher I was waiting for an OK here to create the PR. BUT, since I got no answer ... I'll create the PR so that at least people can have a branch to point to, and will push to make it merged.. |
Thank you @morenocarullo, using your fix as well. +1 for getting an official fix merged |
FYI, I am preparing a PR for this issue. To begin with, we'll have a fork with the fix applied which is slightly better than the module-drop-in there, but I really want to make it upstream into the official branch. |
PR is here: #5474 Feel free to use the referenced branch/fork while we wait for it to be merged. |
This: waiting-for-dev/devise-jwt#235 (comment) |
Hi, I am facing this error test "should get index" do
sign_in users(:one)
get movies_url, as: :json
assert_response :success
end but even having both workarounds (the one in application.rb and the other having RackSessionFix.rb) is not working. Any ideas? Thanks. |
As described in https://github.com/wardencommunity/warden/blob/master/lib/warden/proxy.rb#L167 need to pass So adding def sign_up(resource_name, resource)
sign_in(resource_name, resource, store: false)
end in your controller inherited from |
In case this helps someone, you'll also need to pass in This needs to be added to the controller inherited from def auth_options
super.merge({store: false})
end |
Hi, any new about a fix ? Thx :) This worked for me :
|
No news :), but thanks for putting it into my radar again, I'll try to take a better look at the problem and the proposed solution(s) here. Thanks. |
`authenticate_user!` * This is a known issue reported here: heartcombo/devise#5443 * There's also an open PR to devise for fixing it: heartcombo/devise#5474 * If the PR gets merged eventually, this fix/patch won't be necessary anymore.
Any reason this is still held up ? |
I'm using v1.2.3 with Rails 7.1, for me the workaround was pretty simple: setting bypass_sign_in as false, to avoid call to Devise's bypass_sign_in (which uses session). Of course for those who needs bypass_sign_in as true, this is still an issue. |
Pre Check
rails new test_app --api
rails g devise:install
rails g devise User
/users
and see the error stated belowEnvironment
Current behavior
When using authenticate_user! on a controller on a rails API only app I am getting the following error:
ActionDispatch::Request::Session::DisabledSessionError (Your application has sessions disabled. To write to the session you must first configure a session store):
Expected behavior
It should throw fail or success on warden depending on if the user is signed in or not.
The text was updated successfully, but these errors were encountered: