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

38 lines
1.1 KiB
JavaScript

export default defineNuxtRouteMiddleware(async (to, from) => {
// Skip auth check for public routes
const publicRoutes = ['/login', '/logout'];
if (publicRoutes.includes(to.path)) {
return;
}
if (process.client) {
try {
// Validate authentication with new endpoint
const { data: validateUser } = await useFetch("/api/auth/validate", {
method: "GET",
server: false // Client-side only
});
// If user is not logged in, redirect to login page
if (validateUser.value && validateUser.value.statusCode === 401) {
const { $swal } = useNuxtApp();
if ($swal) {
await $swal.fire({
title: "Authentication Required",
text: "Please log in to access this page.",
icon: "warning",
confirmButtonText: "Login",
allowOutsideClick: false
});
}
return navigateTo('/login');
}
} catch (error) {
console.error('Auth middleware error:', error);
return navigateTo('/login');
}
}
});