49 lines
1007 B
TypeScript
49 lines
1007 B
TypeScript
|
import { NavigationGuardWithThis, RouteRecordRaw } from 'vue-router';
|
||
|
import Dashboard from '../views/Dashboard.vue';
|
||
|
import Login from '../views/Login.vue';
|
||
|
import { createRouter, createWebHashHistory } from 'vue-router';
|
||
|
import { useUserStore } from '../store/user.store';
|
||
|
import HousePlanner from '../components/house-planner/HousePlanner.vue';
|
||
|
|
||
|
const routes: RouteRecordRaw[] = [
|
||
|
{
|
||
|
name: 'dashboard',
|
||
|
path: '/',
|
||
|
component: Dashboard,
|
||
|
},
|
||
|
{
|
||
|
name: 'login',
|
||
|
path: '/login',
|
||
|
component: Login,
|
||
|
},
|
||
|
{
|
||
|
name: 'planner',
|
||
|
path: '/planner',
|
||
|
component: HousePlanner,
|
||
|
meta: {
|
||
|
authenticated: false,
|
||
|
},
|
||
|
},
|
||
|
];
|
||
|
|
||
|
const router = createRouter({
|
||
|
history: createWebHashHistory(),
|
||
|
routes,
|
||
|
});
|
||
|
|
||
|
router.beforeEach(async (to, from, next) => {
|
||
|
const userStore = useUserStore();
|
||
|
|
||
|
if (
|
||
|
to.name !== 'login' &&
|
||
|
to.meta?.authenticated !== false &&
|
||
|
!userStore.isLoggedIn
|
||
|
) {
|
||
|
return next({ name: 'login' });
|
||
|
}
|
||
|
|
||
|
next();
|
||
|
});
|
||
|
|
||
|
export default router;
|