24 lines
905 B
TypeScript
24 lines
905 B
TypeScript
// server/api/hak-akses/check.ts
|
|
export default defineEventHandler(async (event) => {
|
|
// This is a mock endpoint to simulate backend checking permission.
|
|
// In production, the backend will validate the user's token directly.
|
|
const method = event.method;
|
|
if (method === 'POST') {
|
|
const body = await readBody(event);
|
|
const { menuKey, action } = body;
|
|
|
|
// Simulating some random failure or checking logic
|
|
if (!menuKey || !action) {
|
|
return createError({ statusCode: 400, statusMessage: 'Bad Request: menuKey and action required' });
|
|
}
|
|
|
|
// Just simulating success for now.
|
|
return {
|
|
success: true,
|
|
message: `Mock check: User has ${action} permission for ${menuKey}`,
|
|
allowed: true
|
|
}
|
|
}
|
|
return createError({ statusCode: 405, statusMessage: 'Method Not Allowed' });
|
|
});
|