in App.vue I get user data (if he is authorized)
onMounted( async () => {
await init();
});
added the initialization function to the useAuthComposables file
import { authService } from '@/shared/services/v1/auth.service';
import { useAuthStore } from '@/store/auth';
export default function () {
const authStore = useAuthStore();
const init = async () => {
const [error, data] = await authService.getAuthUser();
if (error) {
console.log(error);
} else {
authStore.setUser(data);
authStore.setToken(true);
}
};
return {
init
};
}
and the store itself useAuthStore
import { defineStore } from 'pinia';
export const useAuthStore = defineStore('authStore', {
state: () => ({
user: null,
isLoggedIn: false
}),
actions: {
setUser(data: any) {
this.user = data;
},
setToken(isAuth: boolean) {
this.isLoggedIn = isAuth;
}
},
getters: {
getUser(state: any) {
return state.user;
}
}
});
when I reload the page (f5) in the route does not see the side
router.beforeEach(async (to, from, next): Promise<any> => {
const authStore = useAuthStore();
console.log('beforeEach',authStore.getUser);
if (!authStore.isLoggedIn) {
next({ name: 'Login' });
}
else {
next();
}
});
but when I just follow the links, it displays a stor