You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
833 B
30 lines
833 B
import { eventHandler, getQuery } from 'h3';
|
|
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
import { MOCK_MENU_LIST } from '~/utils/mock-data';
|
|
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
|
|
const namesMap: Record<string, any> = {};
|
|
|
|
function getNames(menus: any[]) {
|
|
menus.forEach((menu) => {
|
|
namesMap[menu.name] = String(menu.id);
|
|
if (menu.children) {
|
|
getNames(menu.children);
|
|
}
|
|
});
|
|
}
|
|
getNames(MOCK_MENU_LIST);
|
|
|
|
export default eventHandler(async (event) => {
|
|
const userinfo = verifyAccessToken(event);
|
|
if (!userinfo) {
|
|
return unAuthorizedResponse(event);
|
|
}
|
|
const { id, name } = getQuery(event);
|
|
|
|
return (name as string) in namesMap &&
|
|
(!id || namesMap[name as string] !== String(id))
|
|
? useResponseSuccess(true)
|
|
: useResponseSuccess(false);
|
|
});
|