fix(FE) : remove logging
This commit is contained in:
+28
-28
@@ -4,17 +4,17 @@ import { useAuth } from '~/composables/useAuth';
|
||||
import { useUserMenuStore } from '~/store/userMenu';
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to: RouteLocationNormalized) => {
|
||||
console.log('🛡️ Auth middleware triggered for:', to.path);
|
||||
// console.log('🛡️ Auth middleware triggered for:', to.path);
|
||||
|
||||
// Allow the login page and access denied page without checks
|
||||
if (to.path === '/auth/login' || to.path === '/auth/access-denied') {
|
||||
console.log('⏭️ Allowing access to auth page:', to.path);
|
||||
// console.log('⏭️ Allowing access to auth page:', to.path);
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip middleware on server-side - auth plugin handles client-side initialization
|
||||
if (process.server) {
|
||||
console.log('⏭️ Server-side: Skipping auth check (plugin will handle on client)');
|
||||
// console.log('⏭️ Server-side: Skipping auth check (plugin will handle on client)');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export default defineNuxtRouteMiddleware(async (to: RouteLocationNormalized) =>
|
||||
|
||||
// Special handling for authentication redirect from Keycloak callback
|
||||
if (isAuthRedirect) {
|
||||
console.log('🔐 Authentication redirect detected');
|
||||
// console.log('🔐 Authentication redirect detected');
|
||||
|
||||
// Give browser a moment to process the cookie from redirect
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
@@ -35,11 +35,11 @@ export default defineNuxtRouteMiddleware(async (to: RouteLocationNormalized) =>
|
||||
await checkAuth();
|
||||
|
||||
if (user.value) {
|
||||
console.log('✅ Session verified after redirect:', user.value.name);
|
||||
// console.log('✅ Session verified after redirect:', user.value.name);
|
||||
// Clean up query parameter
|
||||
return navigateTo({ path: to.path, query: {} }, { replace: true });
|
||||
} else {
|
||||
console.error('❌ Session verification failed after redirect');
|
||||
// console.error('❌ Session verification failed after redirect');
|
||||
return navigateTo('/auth/login?error=session_failed');
|
||||
}
|
||||
}
|
||||
@@ -48,19 +48,19 @@ export default defineNuxtRouteMiddleware(async (to: RouteLocationNormalized) =>
|
||||
// User state should already be populated by auth plugin
|
||||
// Only call checkAuth if user state is not available (edge case)
|
||||
if (!user.value) {
|
||||
console.log('⚠️ User not in state, verifying session...');
|
||||
// console.log('⚠️ User not in state, verifying session...');
|
||||
await checkAuth();
|
||||
}
|
||||
|
||||
if (user.value) {
|
||||
console.log('✅ User authenticated:', user.value.name);
|
||||
// console.log('✅ User authenticated:', user.value.name);
|
||||
|
||||
// Authorization Check: Verify if user has access to the requested path
|
||||
const menuStore = useUserMenuStore();
|
||||
|
||||
// Check if user has no access (role inactive)
|
||||
if (menuStore.noAccess) {
|
||||
console.warn('⛔ User has no access (role inactive or no permissions)');
|
||||
// console.warn('⛔ User has no access (role inactive or no permissions)');
|
||||
return navigateTo({
|
||||
path: '/auth/access-denied',
|
||||
query: { reason: 'no_role_or_inactive' }
|
||||
@@ -74,16 +74,16 @@ export default defineNuxtRouteMiddleware(async (to: RouteLocationNormalized) =>
|
||||
if (!isPublicPath) {
|
||||
// If menu is not fetched yet, wait for it to load (with timeout)
|
||||
if (!menuStore.menuFetched) {
|
||||
console.log('⏳ Menu not fetched yet, loading...');
|
||||
// console.log('⏳ Menu not fetched yet, loading...');
|
||||
|
||||
const token = localStorage.getItem('idToken');
|
||||
if (token && user.value.id) {
|
||||
try {
|
||||
// Try to load menu
|
||||
await menuStore.fetchUserMenu(user.value.id, token);
|
||||
console.log('✅ Menu loaded in middleware');
|
||||
// console.log('✅ Menu loaded in middleware');
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to load menu in middleware:', error);
|
||||
// console.error('❌ Failed to load menu in middleware:', error);
|
||||
// If menu fails to load, deny access by default for security
|
||||
return navigateTo({
|
||||
path: '/auth/access-denied',
|
||||
@@ -91,7 +91,7 @@ export default defineNuxtRouteMiddleware(async (to: RouteLocationNormalized) =>
|
||||
}, { replace: true });
|
||||
}
|
||||
} else {
|
||||
console.error('❌ Cannot load menu: No token or user ID');
|
||||
// console.error('❌ Cannot load menu: No token or user ID');
|
||||
return navigateTo('/auth/login');
|
||||
}
|
||||
}
|
||||
@@ -167,47 +167,47 @@ export default defineNuxtRouteMiddleware(async (to: RouteLocationNormalized) =>
|
||||
);
|
||||
if (hasAllRequired) {
|
||||
grantedByDependency = true;
|
||||
console.log('✅ Access granted by dependency:', {
|
||||
requestedPath: to.path,
|
||||
satisfiedDependencies: requiredPaths
|
||||
});
|
||||
// console.log('✅ Access granted by dependency:', {
|
||||
// requestedPath: to.path,
|
||||
// satisfiedDependencies: requiredPaths
|
||||
// });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('🔐 Authorization check:', {
|
||||
requestedPath: to.path,
|
||||
eligiblePaths: Array.from(eligiblePaths),
|
||||
hasAccess,
|
||||
grantedByDependency
|
||||
});
|
||||
// console.log('🔐 Authorization check:', {
|
||||
// requestedPath: to.path,
|
||||
// eligiblePaths: Array.from(eligiblePaths),
|
||||
// hasAccess,
|
||||
// grantedByDependency
|
||||
// });
|
||||
|
||||
if (!hasAccess && !grantedByDependency) {
|
||||
console.warn('⛔ Access denied: User does not have permission to access', to.path);
|
||||
// console.warn('⛔ Access denied: User does not have permission to access', to.path);
|
||||
return navigateTo({
|
||||
path: '/auth/access-denied',
|
||||
query: { path: to.path }
|
||||
}, { replace: true });
|
||||
}
|
||||
|
||||
console.log('✅ Authorization granted for:', to.path);
|
||||
// console.log('✅ Authorization granted for:', to.path);
|
||||
} else {
|
||||
// Menu fetched but empty (no access)
|
||||
console.error('❌ Menu is empty, denying access for security');
|
||||
// console.error('❌ Menu is empty, denying access for security');
|
||||
return navigateTo({
|
||||
path: '/auth/access-denied',
|
||||
query: { path: to.path, reason: 'no_permissions' }
|
||||
}, { replace: true });
|
||||
}
|
||||
} else {
|
||||
console.log('✅ Public path, skipping authorization:', to.path);
|
||||
// console.log('✅ Public path, skipping authorization:', to.path);
|
||||
}
|
||||
|
||||
return; // Allow access
|
||||
} else {
|
||||
console.log('❌ No active session, redirecting to login');
|
||||
// console.log('❌ No active session, redirecting to login');
|
||||
return navigateTo('/auth/login');
|
||||
}
|
||||
});
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { ref, computed, watch, onMounted } from 'vue';
|
||||
import { Icon } from '@iconify/vue';
|
||||
// @ts-ignore: module has incompatible/undiscoverable typings in package exports
|
||||
import VueApexCharts from "vue3-apexcharts";
|
||||
import ModalPendaftaran from '@/components/pendaftaran/ModalPendaftaran.vue';
|
||||
import ModalPendaftaran from '@/components/pendaftaran/ModalPendaftaranV2.vue';
|
||||
import api from '@/services/api';
|
||||
import { useAuth } from '~/composables/useAuth';
|
||||
import { useUserMenuStore } from '~/store/userMenu';
|
||||
|
||||
Reference in New Issue
Block a user