diff --git a/backend/src/controllers/admin.cpp b/backend/src/controllers/admin.cpp index 9de8720..9db135e 100644 --- a/backend/src/controllers/admin.cpp +++ b/backend/src/controllers/admin.cpp @@ -88,5 +88,9 @@ namespace api { cbk(dto::Responses::get_badreq_res("Validation error")); } } + + void admin::is_admin(req_type, cbk_type cbk) { + cbk(dto::Responses::get_success_res()); + } } #pragma clang diagnostic pop \ No newline at end of file diff --git a/backend/src/controllers/controllers.h b/backend/src/controllers/controllers.h index fa2a8c1..fe43de7 100644 --- a/backend/src/controllers/controllers.h +++ b/backend/src/controllers/controllers.h @@ -24,6 +24,7 @@ public: METHOD_ADD(admin::logout, "/logout", drogon::Post, "Login", "Admin"); METHOD_ADD(admin::delete_user, "/delete", drogon::Post, "Login", "Admin"); METHOD_ADD(admin::disable_2fa, "/disable_2fa", drogon::Post, "Login", "Admin"); + METHOD_ADD(admin::is_admin, "/is_admin", drogon::Get, "Login", "Admin"); METHOD_LIST_END void users(req_type, cbk_type); @@ -31,6 +32,7 @@ public: void logout(req_type, cbk_type); void delete_user(req_type, cbk_type); void disable_2fa(req_type, cbk_type); + void is_admin(req_type, cbk_type); }; class auth : public drogon::HttpController { diff --git a/frontend/src/App.vue b/frontend/src/App.vue index ce980a3..54e6c2c 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -5,6 +5,7 @@ import { useRouter, RouterLink } from 'vue-router'; import type { TokenInjectType } from '@/api'; import { useMessage, NMenu, NPageHeader, NIcon } from 'naive-ui'; import { BareMetalServer02 } from '@vicons/carbon'; +import { is_admin } from '@/api/admin'; const router = useRouter(); const message = useMessage(); @@ -69,6 +70,19 @@ const menuOptions: MenuOption[] = [ key: 'login' } ]; + +if (await is_admin(jwt.value ?? '')) + menuOptions.unshift({ + label: () => + h( + RouterLink, + { + to: '/admin' + }, + { default: () => 'Admin' } + ), + key: 'admin' + });