March 7, 2022
By default, when a userâs session expires with a Livewire component open on the page, Livewire shows this message:
This page has expired. Would you like to refresh the page?
Livewire probably opts to ask first instead of just refreshing the page since the user could have unsaved content on the page that they donât want to lose.
However, in some apps there isnât much ability to have unsaved content on the page, and Iâd just like to refresh the page without annoying the user by asking them.
To override this behavior when the page expires, Laravel provides a hook called onPageExpired
. Put this JavaScript after Livewire has loaded (by either placing it below Livewireâs scripts in your HTML, or in a JavaScript file thatâs loaded with the defer
attribute):
Livewire.onPageExpired((response, message) => {
location.reload()
})
In this example, I just reload the page without asking the user first. Hopefully, they wonât notice that the page expired at all.
Alternatively, you could use JavaScript to do your own message through [confirm()](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm)
, or show a custom-designed dialog window that tells the user that their session has expired.
Tufts Meal Plan Wrapped
Mar 2, 2024
Building an e-ink picture frame that displays an iCloud photo album
Jan 9, 2024
2023 in review
Jan 5, 2024
Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iâm working on!