Created
October 31, 2022 17:42
-
-
Save davidteren/c564b734ee0f9286b95d9bba104745e9 to your computer and use it in GitHub Desktop.
A simple solution for Rails 7 (Hotwire) & Devise sessions destroy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In config/route.rb | |
Rails.application.routes.draw do | |
# other routes... | |
# Allows us to use link_to for session destroy | |
devise_scope :user do | |
get "/users/sign_out", as: "sign_out", to: "devise/sessions#destroy" | |
end | |
end | |
# In views | |
<% if user_signed_in? %> | |
<%= link_to "Sign Out", sign_out_path %> | |
<% else %> | |
<%= link_to "Sign In", new_user_session_path %> | |
<% end %> |
@rubyhcm, I was under the impression that this issue had been addressed in Devise 🤷♂️
You can just change the config
Devise.setup do |config|
config.sign_out_via = :get
end
I was under the impression that this issue had been addressed in Devise
yeah, in rails 7. I use
<%= link_to "Sign out", destroy_user_session_path, data: { turbo_method: :delete } %>
Right! That's how it should be.
But I'm having bugs when using it with data-turbo-permanent
on my navbar where the logout button is located. After reloading the DOM is a mess 😄 (I'm also using <%= turbo_refreshes_with method: :morph, scroll: :preserve %>
)
So I came up with data: { turbo: false }
on a link, and moving to get
request
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works well