Afiq 379eb17246 Implement Authentik Integration and Simplify RBAC Structure
- Updated nuxt.config.js to include Authentik configuration and public keys for client-side access.
- Introduced a new composable, useAuth.js, for handling authentication logic with Authentik, including user validation, login, and logout functionalities.
- Enhanced documentation to reflect the simplified RBAC structure and the integration of Authentik, emphasizing user-centric design and streamlined permission management.
- Refactored middleware for authentication checks and improved error handling during user validation.
- Created new pages for login and dashboard, ensuring proper routing and user experience.
- Removed obsolete Metabase integration and unnecessary complexity from the project structure.
2025-05-31 19:15:21 +08:00

73 lines
1.8 KiB
JavaScript

import { authentikFetch } from '../../utils/authentik';
import { requireAuth } from '../../utils/auth';
// /api/applications/[id] - Handle GET, PUT, DELETE for specific application
export default defineEventHandler(async (event) => {
const method = getMethod(event);
const id = getRouterParam(event, 'id');
// Require authentication
await requireAuth(event);
if (!id) {
throw createError({
statusCode: 400,
message: 'Application ID is required'
});
}
switch (method) {
case 'GET':
try {
const application = await authentikFetch(`/core/applications/${id}/`);
return application;
} catch (error) {
throw createError({
statusCode: error.statusCode || 404,
message: error.message || 'Application not found'
});
}
case 'PUT':
try {
const body = await readBody(event);
const application = await authentikFetch(`/core/applications/${id}/`, {
method: 'PUT',
body: {
name: body.name,
slug: body.slug,
meta_description: body.description,
meta_publisher: 'CorradAF RBAC'
}
});
return application;
} catch (error) {
throw createError({
statusCode: error.statusCode || 500,
message: error.message
});
}
case 'DELETE':
try {
await authentikFetch(`/core/applications/${id}/`, {
method: 'DELETE'
});
return { message: 'Application deleted successfully' };
} catch (error) {
throw createError({
statusCode: error.statusCode || 500,
message: error.message
});
}
default:
throw createError({
statusCode: 405,
message: 'Method not allowed'
});
}
});