Clear offline cache when logging out
Adds a logout Stimulus controller that sends a message to the service
worker to clear all cached content when the user logs out. This ensures
that cached data from one user isn't accessible after logout.
The implementation:
- Adds logout_controller.js that posts { action: "clearCache" } to the
service worker via postMessage
- Updates logout buttons to use the controller on form submission
Also fixes data-turbo placement: moved from button to form element where
it actually takes effect for disabling Turbo Drive form submissions.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ GIT
|
|||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: https://github.com/hotwired/turbo-rails.git
|
remote: https://github.com/hotwired/turbo-rails.git
|
||||||
revision: 49be3f2d43edeeedad48cb492b35242fdb27af74
|
revision: 45a2a40be0a677808a3a269311f1b5abaa3b30ba
|
||||||
branch: offline-cache
|
branch: offline-cache
|
||||||
specs:
|
specs:
|
||||||
turbo-rails (2.0.21)
|
turbo-rails (2.0.21)
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@ GIT
|
|||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: https://github.com/hotwired/turbo-rails.git
|
remote: https://github.com/hotwired/turbo-rails.git
|
||||||
revision: 49be3f2d43edeeedad48cb492b35242fdb27af74
|
revision: 45a2a40be0a677808a3a269311f1b5abaa3b30ba
|
||||||
branch: offline-cache
|
branch: offline-cache
|
||||||
specs:
|
specs:
|
||||||
turbo-rails (2.0.21)
|
turbo-rails (2.0.21)
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { Controller } from "@hotwired/stimulus"
|
||||||
|
|
||||||
|
export default class extends Controller {
|
||||||
|
async clearCache() {
|
||||||
|
const registration = await navigator.serviceWorker?.ready
|
||||||
|
registration?.active?.postMessage({ action: "clearCache" })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<%= tag.li class: "popup__item", data: { filter_target: "item", navigable_list_target: "item" } do %>
|
<%= tag.li class: "popup__item", data: { filter_target: "item", navigable_list_target: "item" } do %>
|
||||||
<%= icon_tag "logout", class: "popup__icon" %>
|
<%= icon_tag "logout", class: "popup__icon" %>
|
||||||
<%= button_to session_path(script_name: nil), method: :delete, class: "popup__btn btn", data: { turbo: false } do %>
|
<%= button_to session_path(script_name: nil), method: :delete, class: "popup__btn btn", form: { data: { turbo: false, controller: "logout", action: "submit->logout#clearCache" } } do %>
|
||||||
<span>Sign out</span>
|
<span>Sign out</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<% if Current.user == @user %>
|
<% if Current.user == @user %>
|
||||||
<hr class="separator--horizontal full-width flex-item-grow margin-block-start-double" style="--border-color: var(--color-ink-light);" aria-hidden="true">
|
<hr class="separator--horizontal full-width flex-item-grow margin-block-start-double" style="--border-color: var(--color-ink-light);" aria-hidden="true">
|
||||||
|
|
||||||
<%= button_to session_path(script_name: nil), method: :delete, class: "btn txt-x-small center", data: { turbo: false } do %>
|
<%= button_to session_path(script_name: nil), method: :delete, class: "btn txt-x-small center", form: { data: { turbo: false, controller: "logout", action: "submit->logout#clearCache" } } do %>
|
||||||
<span>Sign out of Fizzy on this device</span>
|
<span>Sign out of Fizzy on this device</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user