restore frontend session
This commit is contained in:
parent
24f437cac6
commit
bc62a25a8e
11 changed files with 146 additions and 14 deletions
|
|
@ -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',
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue