This commit is contained in:
2025-01-04 21:01:04 +03:30
parent aad48fca63
commit 57d328bbfe
33 changed files with 1752 additions and 261 deletions
+45
View File
@@ -1,5 +1,29 @@
import AppLayout from '@/layout/AppLayout.vue';
import { createRouter, createWebHistory } from 'vue-router';
import axios from 'axios';
import Cookies from 'js-cookie';
const loginGuard = async (to, from, next) => {
const token = Cookies.get('bm-token');
if (!token) {
next('/auth/login'); // Redirect to log in if no token
return;
}
try {
const response = await axios.get('/api/users/user/get-self', {
headers: {
Authorization: `Bearer ${token}`
},
withCredentials: true
});
next();
} catch (error) {
console.log('Authentication error:', error);
next('/auth/login');
}
};
const router = createRouter({
history: createWebHistory(),
@@ -7,12 +31,33 @@ const router = createRouter({
{
path: '/',
component: AppLayout,
beforeEnter: loginGuard,
children: [
{
path: '/',
name: 'dashboard',
component: () => import('@/views/Dashboard.vue')
},
{
path: '/belonging/create-belonging',
name: 'create-belonging',
component: () => import('@/views/pages/Belonging/CreateBelonging.vue')
},
{
path: '/belonging/list-belongings',
name: 'list-belongings',
component: () => import('@/views/pages/Belonging/ListBelongings.vue')
},
{
path: '/categories/list-categories',
name: 'list-categories',
component: () => import('@/views/pages/Category/ListCategories.vue')
},
{
path: '/features/list-features',
name: 'list-features',
component: () => import('@/views/pages/Features/ListFeatures.vue')
},
{
path: '/uikit/formlayout',
name: 'formlayout',