Added endpoint for checking if user is an admin
This commit is contained in:
		@@ -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'
 | 
			
		||||
	});
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<template>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
import type { Requests, Responses } from '@/dto';
 | 
			
		||||
import { UserRole, get_token, post_token } from './base';
 | 
			
		||||
import { UserRole, get_token, post_token, isErrorResponse } from './base';
 | 
			
		||||
 | 
			
		||||
export const get_users = (token: string): Promise<Responses.GetUsers> =>
 | 
			
		||||
	get_token('/api/admin/users', token);
 | 
			
		||||
@@ -53,3 +53,6 @@ export const disable_tfa = (
 | 
			
		||||
		},
 | 
			
		||||
		token
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
export const is_admin = async (token: string): Promise<boolean> =>
 | 
			
		||||
	!isErrorResponse(await get_token('/api/admin/is_admin', token));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user