feat:menambahkan fitur superadmin
This commit is contained in:
+14
-1
@@ -8,7 +8,8 @@ import DashboardView from "../views/DashboardView.vue"
|
||||
import SavedView from "../views/SavedView.vue"
|
||||
import LoginView from "../views/LoginView.vue"
|
||||
import RegisterView from "../views/RegisterView.vue"
|
||||
import { getToken } from "../utils"
|
||||
import AdminProductsView from "../views/AdminProductsView.vue"
|
||||
import { getCurrentUser, getToken } from "../utils"
|
||||
|
||||
const routes = [
|
||||
{ path: "/", name: "home", component: HomeView },
|
||||
@@ -17,6 +18,12 @@ const routes = [
|
||||
{ path: "/jual", name: "sell-product", component: SellProductView, meta: { requiresAuth: true } },
|
||||
{ path: "/dashboard", name: "dashboard", component: DashboardView, meta: { requiresAuth: true } },
|
||||
{ path: "/tersimpan", name: "saved", component: SavedView, meta: { requiresAuth: true } },
|
||||
{
|
||||
path: "/admin/products",
|
||||
name: "admin-products",
|
||||
component: AdminProductsView,
|
||||
meta: { requiresAuth: true, requiresSuperadmin: true }
|
||||
},
|
||||
{ path: "/login", name: "login", component: LoginView },
|
||||
{ path: "/register", name: "register", component: RegisterView }
|
||||
]
|
||||
@@ -30,6 +37,12 @@ router.beforeEach((to) => {
|
||||
if (to.meta.requiresAuth && !getToken()) {
|
||||
return "/login"
|
||||
}
|
||||
|
||||
const user = getCurrentUser()
|
||||
|
||||
if (to.meta.requiresSuperadmin && user?.role !== "superadmin") {
|
||||
return "/dashboard"
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user