restore frontend session

This commit is contained in:
Yisroel Baum 2026-07-31 11:05:05 +03:00
parent 24f437cac6
commit bc62a25a8e
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
11 changed files with 146 additions and 14 deletions

View file

@ -37,21 +37,31 @@ const router = createRouter({
],
})
router.beforeEach((to) => {
router.beforeEach(async (to) => {
const authStore = useAuthStore()
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
return {
name: 'login',
query: {
redirect: to.fullPath,
},
const restoredSession = await authStore.fetchMe()
if (!restoredSession) {
return {
name: 'login',
query: {
redirect: to.fullPath,
},
}
}
}
if (to.meta.guestOnly && authStore.isAuthenticated) {
return {
name: 'dashboard',
if (to.meta.guestOnly) {
let restoredSession = authStore.isAuthenticated
if (!restoredSession) {
restoredSession = await authStore.fetchMe()
}
if (restoredSession) {
return {
name: 'dashboard',
}
}
}
})