- 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.
25 lines
690 B
JavaScript
25 lines
690 B
JavaScript
export default defineNuxtRouteMiddleware(async (to, from) => {
|
|
// Skip if already on dashboard
|
|
if (to.path === '/dashboard') {
|
|
return;
|
|
}
|
|
|
|
if (process.client) {
|
|
try {
|
|
// Check if user is authenticated
|
|
const { data: validateUser } = await useFetch("/api/auth/validate", {
|
|
method: "GET",
|
|
server: false
|
|
});
|
|
|
|
// If user is authenticated, redirect to dashboard
|
|
if (validateUser.value && validateUser.value.statusCode === 200) {
|
|
return navigateTo("/dashboard");
|
|
}
|
|
} catch (error) {
|
|
// If validation fails, continue to the requested route
|
|
console.error('Dashboard middleware error:', error);
|
|
}
|
|
}
|
|
});
|