Check If User Is Logged In Laravel Sanctum With Vuejs Spa
I am trying to solve this but I can't, I have a website built with Laravel and Vuejs: This is my app.js import 'bootstrap'; import './axios'; import Vue from 'vue'; import VueRoute
Solution 1:
I was able to solve this problem, but I don't know if this is the best way to do it:
in my app.js Instead of this:
store.dispatch('checkAuth');
    
    const app = new Vue({
        el: '#app',
        store ,
        router
    });
I did this:
constVueInstance = ()=>{
  newVue({
            el: '#app',
            store ,
            router
        });
}
store.dispatch('checkAuth').then(()=>{
    VueInstance();
}).catch(()=>{
    VueInstance();
});
Now it is working because the vuex action checkAuth returns a promise, so I needed to wait until it is completed, but, in case the action returns an error, because in the first load the user is not logged in, I must add a catch, because th Vue should be created whether the user is logged in or not. If someone have a better solution let me know. Thank you.
Post a Comment for "Check If User Is Logged In Laravel Sanctum With Vuejs Spa"