|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import { Role } from '@/Enum/Role'
|
|
|
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
|
|
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
|
|
|
|
|
|
|
|
const routes: Array<RouteRecordRaw> = [
|
|
const routes: Array<RouteRecordRaw> = [
|
|
@@ -20,31 +21,37 @@ const routes: Array<RouteRecordRaw> = [
|
|
|
path: '/dashboard',
|
|
path: '/dashboard',
|
|
|
name: 'dashboard',
|
|
name: 'dashboard',
|
|
|
component: () => import('../views/DashboardView.vue'),
|
|
component: () => import('../views/DashboardView.vue'),
|
|
|
- meta: { requiresAuth: true }
|
|
|
|
|
|
|
+ meta: { requiresAuth: true, roles: [Role.Admin] }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ path: '/dashboard/:id',
|
|
|
|
|
+ name: 'dashboard company',
|
|
|
|
|
+ component: () => import('../views/DashboardView.vue'),
|
|
|
|
|
+ meta: { requiresAuth: true, roles: [Role.Admin, Role.Manager] }
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
path: '/companies',
|
|
path: '/companies',
|
|
|
name: 'companies',
|
|
name: 'companies',
|
|
|
component: () => import('../views/CompanyView.vue'),
|
|
component: () => import('../views/CompanyView.vue'),
|
|
|
- meta: { requiresAuth: true }
|
|
|
|
|
|
|
+ meta: { requiresAuth: true, roles: [Role.Admin, Role.Manager] }
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
path: '/employees',
|
|
path: '/employees',
|
|
|
name: 'employees',
|
|
name: 'employees',
|
|
|
component: () => import('../views/EmployeeView.vue'),
|
|
component: () => import('../views/EmployeeView.vue'),
|
|
|
- meta: { requiresAuth: true }
|
|
|
|
|
|
|
+ meta: { requiresAuth: true, roles: [Role.Admin, Role.Manager] }
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
path: '/trips',
|
|
path: '/trips',
|
|
|
name: 'trips',
|
|
name: 'trips',
|
|
|
component: () => import('../views/TripView.vue'),
|
|
component: () => import('../views/TripView.vue'),
|
|
|
- meta: { requiresAuth: true }
|
|
|
|
|
|
|
+ meta: { requiresAuth: true, roles: [Role.Admin, Role.Manager, Role.Driver, Role.Employee, Role.User] }
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
path: '/vehicles',
|
|
path: '/vehicles',
|
|
|
name: 'vehicles',
|
|
name: 'vehicles',
|
|
|
component: () => import('../views/VehicleView.vue'),
|
|
component: () => import('../views/VehicleView.vue'),
|
|
|
- meta: { requiresAuth: true }
|
|
|
|
|
|
|
+ meta: { requiresAuth: true, roles: [Role.Admin, Role.Manager, Role.Driver, Role.Employee] }
|
|
|
},
|
|
},
|
|
|
// {
|
|
// {
|
|
|
// path: '/budget',
|
|
// path: '/budget',
|
|
@@ -62,13 +69,13 @@ const routes: Array<RouteRecordRaw> = [
|
|
|
path: '/drivers',
|
|
path: '/drivers',
|
|
|
name: 'drivers',
|
|
name: 'drivers',
|
|
|
component: () => import('../views/DriverView.vue'),
|
|
component: () => import('../views/DriverView.vue'),
|
|
|
- meta: { requiresAuth: true }
|
|
|
|
|
|
|
+ meta: { requiresAuth: true, roles: [Role.Admin, Role.Manager, Role.Driver, Role.Employee, Role.User]}
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
path: '/verification-profil',
|
|
path: '/verification-profil',
|
|
|
name: 'profile-verification',
|
|
name: 'profile-verification',
|
|
|
component: () => import('../views/ProfileVerificationView.vue'),
|
|
component: () => import('../views/ProfileVerificationView.vue'),
|
|
|
- meta: { requiresAuth: true }
|
|
|
|
|
|
|
+ meta: { requiresAuth: true , roles: [Role.Admin, Role.Manager, Role.Driver, Role.Employee, Role.User] }
|
|
|
},
|
|
},
|
|
|
// {
|
|
// {
|
|
|
// path: '/company-setup',
|
|
// path: '/company-setup',
|
|
@@ -91,14 +98,24 @@ const routes: Array<RouteRecordRaw> = [
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
const router = createRouter({
|
|
|
- history: createWebHistory(import.meta.env.BASE_URL),
|
|
|
|
|
|
|
+ history: createWebHistory((import.meta as any).env.BASE_URL),
|
|
|
routes
|
|
routes
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
router.beforeEach((to, from, next) => {
|
|
|
const token = localStorage.getItem('token')
|
|
const token = localStorage.getItem('token')
|
|
|
|
|
+ const userRole = localStorage.getItem('userRole')
|
|
|
if (to.meta.requiresAuth && !token) {
|
|
if (to.meta.requiresAuth && !token) {
|
|
|
next('/login')
|
|
next('/login')
|
|
|
|
|
+ } else if (to.meta.requiresAuth && token) {
|
|
|
|
|
+ const allowedRoles = to.meta.roles as string[] | undefined
|
|
|
|
|
+ if(allowedRoles && userRole && !allowedRoles.includes(userRole)) {
|
|
|
|
|
+ console.log('Access denied')
|
|
|
|
|
+ next('/login')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ next()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
next()
|
|
next()
|
|
|
}
|
|
}
|