am beginner with vuejs. I am doing my first application with Vuejs with laravel sanctum as a package for token based authentication. My problem is when a user is logged in and stay inactive for several hours without signout from application , i got 401 (unauthorized) error after trying to access protected routes.. I must signout and signin again in order to do my jobs.
I am using vuex state management library to preseve the app state.
routes/api.php
Route::post('/login','API\AuthController@login');
Route::middleware('auth:sanctum')->group(function (){
Route::get('/logout','API\AuthController@logout');});
Below is how i am logging in
axios.get('/sanctum/csrf-cookie').then(response => {
// Login...
this.$store.dispatch('login',credentials)
.then((res) => {
this.$store.commit("SET_LOADING",false);
if( this.isAuthenticated && config.getToken() !== 'undefined'){
this.$router.push({ name: 'home'});
window.reload;
}
});});
My vuex store.js
export default new Vuex.Store({
modules: {
auth
},
plugins: [
createPersistedState(
{
storage: window.localStorage
}
)],})
i tried to store my tokens at local storage but i don't think its a best way... What i want is to make a user logged in for much long untill he/she logged out