@vincent15000 You can’t. An event isn’t dispatched when a sessions “expires”. A session “expires” when the file or whatever is cleaned up via garbage collection.
Laravel / VueJS : alert if session expired
Hello,
I handle authentication with Fortify.
I want to show an alert on the message when the session has expired, just to inform the user that he has been logged out and that he needs to log in.
How can I do that ?
I have thought about checking every 5 seconds by sending a request to the server, but this way the session is refreshed every 5 seconds.
I thought about configuring the session lifetime in the front end and check for inactivity, but the session can expire for other reasons than for lifetime.
What would you suggest me ?
Thanks for your help.
V
@vincent15000 The only real option is to forcibly keep the session alive whilst they have a page open on the site.
Whilst you have links on your front-end that go direct to a new page, you have no control over what happens when they click that link. Obviously what you can do is control what the login page looks like to make it a smooth experience.
There is the possibility of creating your own session timer in the browser, but you would need to use shared local storage so that all tabs of your site share the same value. When the timeout occurs show a login modal, collect the login details off the user and submit it to the login endpoint. If the server session is still valid the login wont happen but the session will be refreshed.
Please or to participate in this conversation.