devise
devise copied to clipboard
Return 303 on redirect for Turbo
Turbo uses the DELETE verb directly so when redirecting with a 302 it retains that verb and the routing fails. This change will use status 303 which will force a change to GET which will allow proper redirecting after sign out.
More information can be found in the following issues: https://github.com/hotwired/turbo/issues/84 https://github.com/hotwired/turbo-rails/issues/259 https://github.com/rails/rails/pull/43430
This PR helped my issue. Thank you very much.
However, I had to add notice: option in order to display signed-out message:
def respond_to_on_destroy
# We actually need to hardcode this as Rails default responder doesn't
# support returning empty response on GET request
respond_to do |format|
format.all { head :no_content }
format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name), status: 303, notice: find_message(:signed_out) }
end
end
And the same issue can happen registrations#destroy action. I override destroy action in Devise::RegistrationsController too:
def destroy
resource.destroy
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message! :notice, :destroyed
yield resource if block_given?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name), status: 303, notice: find_message(:destroyed) }
end
I think this is still relevant, as seen here https://github.com/heartcombo/devise/issues/5458
The main branch should contain all that's necessary for fully working with Turbo now, based on the changes here and a few others. A new version will be released soon, but feel free to test it out from the main branch in the meantime, and report back on any issues. Thanks.