Laravel Sanctum SPA - User Lifecycle (Client Side)
Hey all,
I'm using VueJS on the same domain as my Laravel Application. I can successfully log a user in without any problems, but don't know the best way to check if a user is still logged in.
I wanted to see if anyone has any advice regarding handling a users session once a user logs in / if this is handled automatically when I call the API?
I can think of a few ways, to do this such as:
Create a new cookie indicating the user has logged in and set it to expire before the existing Laravel cookies, forcing the user to re-login.
For any 401 results (unauthenticated) prompt the user to log in again. Redirect the user back to the same page they were using and perhaps force them to resubmit the data again.
Every x minutes, attempt to refresh the existing cookies with Laravel, hopefully preventing a 401 response from occurring.
A combination of the above.
Not certain if there are any other options.
Use Cases
User closes and reopens the website.
User leaves website open and comes back in x minutes after cookie has expired.
User is continuously using website and when attempting to hit API method, they get a 401.