corrad-af-2024/server/api/test-authentik.js
Md Afiq Iskandar ef5526baf1 Refactor Application Creation and Management Logic
- Simplified the application creation process by consolidating form fields and enhancing validation.
- Updated the create application page to streamline user experience with clearer provider options and improved layout.
- Implemented SweetAlert for success and error notifications during user actions, replacing traditional alerts.
- Enhanced the applications index page with dynamic filtering and improved data fetching from the Authentik API.
- Refactored API endpoints to utilize slugs for application identification, ensuring consistency with Authentik's structure.
- Improved authentication handling by updating the requireAuth utility to support cookie-based authentication.
2025-06-17 11:53:15 +08:00

46 lines
1.4 KiB
JavaScript

// Simple test endpoint to verify Authentik connection
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig();
try {
console.log('🧪 Testing Authentik connection...');
console.log('🔗 Authentik URL:', config.public.authentikUrl);
console.log('🔑 API Token exists:', !!config.authentik?.apiToken);
console.log('🔑 API Token length:', config.authentik?.apiToken?.length || 0);
// Test basic API access
const response = await $fetch(`${config.public.authentikUrl}/api/v3/core/applications/`, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${config.authentik.apiToken}`
}
});
return {
success: true,
message: 'Authentik connection successful!',
data: {
authentikUrl: config.public.authentikUrl,
applicationsCount: response.results?.length || 0,
tokenExists: !!config.authentik?.apiToken
}
};
} catch (error) {
console.error('❌ Authentik connection test failed:', error);
return {
success: false,
error: {
status: error.response?.status,
message: error.message,
details: error.response?.statusText
},
debugging: {
authentikUrl: config.public.authentikUrl,
tokenExists: !!config.authentik?.apiToken,
tokenLength: config.authentik?.apiToken?.length || 0
}
};
}
});