@pn If you are using Axios... you can write an interceptor that re-logs someone in based on their session.
I do this... basically if an axios call fails auth... it reloads the actual laravel page, literally refreshes the browser window. That will re-generate the laravel session token and automagically log them back in.
// Refresh Laravel Session for Axios
window.axios.interceptors.response.use(
response => {
// Call was successful, don't do anything special.
return response;
},
error => {
if (error.response.status === 401) {
// Reload the page to refresh the laravel_token cookie.
window.location.reload();
}
// If the error is not related to being Unauthorized, reject the promise.
return Promise.reject(error);
}
);
This can be taken a lot further... but I'm fine with this approach since remember tokens are technically forever under the hood. It's like 1 or 5 years and refreshes everytime something is loaded.
This approached solved remember me for my SPA app.
If you want to use a remember me checkbox specifically... you could write that but it wouldn't be real anyway... since ajax login basically auths every call via headers... devices are just assumed logged in until logged out.
Look into Laravel Airlock. I know Taylor Otwell is putting together a solid answer to SPA login with this upcoming package...
https://github.com/laravel/airlock