- 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.
41 lines
926 B
JavaScript
41 lines
926 B
JavaScript
// Validate current authentication status
|
|
export default defineEventHandler(async (event) => {
|
|
const config = useRuntimeConfig();
|
|
|
|
try {
|
|
const authToken = getCookie(event, 'auth_token');
|
|
|
|
if (!authToken) {
|
|
return {
|
|
statusCode: 401,
|
|
message: "Not authenticated - no token found"
|
|
};
|
|
}
|
|
|
|
// Verify token with Authentik
|
|
const userInfo = await $fetch(`${config.public.authentikUrl}/application/o/userinfo/`, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`
|
|
}
|
|
});
|
|
|
|
if (!userInfo) {
|
|
return {
|
|
statusCode: 401,
|
|
message: "Invalid token"
|
|
};
|
|
}
|
|
|
|
return {
|
|
statusCode: 200,
|
|
message: "Authorized",
|
|
user: userInfo
|
|
};
|
|
} catch (error) {
|
|
console.error('Token validation error:', error);
|
|
return {
|
|
statusCode: 401,
|
|
message: "Unauthorized - token validation failed"
|
|
};
|
|
}
|
|
});
|