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' }); } });