diff --git a/composables/useAuth.ts b/composables/useAuth.ts index 5bde15a..14a00d8 100644 --- a/composables/useAuth.ts +++ b/composables/useAuth.ts @@ -16,9 +16,12 @@ export const useAuth = () => { isLoading.value = true clearError() + const headers = import.meta.server ? useRequestHeaders(['cookie']) as Record : {} + // The session API returns SessionResponse, or throws 401 if not authenticated // $fetch automatically sends cookies for same-origin requests const response = await $fetch('/api/auth/session', { + headers, credentials: 'include' // Explicitly include cookies (though $fetch does this by default) }) diff --git a/composables/useHakAkses.ts b/composables/useHakAkses.ts index b120c03..f57a74c 100644 --- a/composables/useHakAkses.ts +++ b/composables/useHakAkses.ts @@ -42,8 +42,9 @@ export const useHakAkses = () => { } try { + const headers = import.meta.server ? useRequestHeaders(['cookie']) as Record : {} // Fetch all hak akses data - const response = await $fetch<{ success: boolean, data: HakAkses[] }>('/api/hak-akses'); + const response = await $fetch<{ success: boolean, data: HakAkses[] }>('/api/hak-akses', { headers }); if (response && response.success && Array.isArray(response.data)) { const hakAksesList = response.data; @@ -95,7 +96,8 @@ export const useHakAkses = () => { const fetchHakAkses = async () => { isLoading.value = true; try { - const response = await $fetch<{ success: boolean, data: HakAkses[] }>('/api/hak-akses'); + const headers = import.meta.server ? useRequestHeaders(['cookie']) as Record : {} + const response = await $fetch<{ success: boolean, data: HakAkses[] }>('/api/hak-akses', { headers }); if (response && response.success) { allHakAksesData.value = response.data; } diff --git a/middleware/checkPageAccess.ts b/middleware/checkPageAccess.ts index 1b98028..a732d07 100644 --- a/middleware/checkPageAccess.ts +++ b/middleware/checkPageAccess.ts @@ -10,6 +10,13 @@ export default defineNuxtRouteMiddleware(async (to, from) => { return; } + // On server-side, skip access check - let client handle it + // This matches auth.ts behavior and prevents SSR failures when cookie context is missing + if (process.server) { + console.log('â­ī¸ Server-side: Skipping page access check (will verify on client)'); + return; + } + // Import useAuth and useHakAkses const { user, checkAuth } = useAuth(); const { getAllowedPages } = useHakAkses(); @@ -27,14 +34,17 @@ export default defineNuxtRouteMiddleware(async (to, from) => { try { const allowedPages = await getAllowedPages(); - // Normalize paths for comparison (optional, but good for robustness) const targetPath = to.path.endsWith('/') && to.path.length > 1 ? to.path.slice(0, -1) : to.path; + const targetPathLower = targetPath.toLowerCase(); + const toPathLower = to.path.toLowerCase(); // Check if user has access to this page - // We also check against the raw path just in case + // We also check against the raw path just in case, case-insensitive const isAllowed = allowedPages.some(path => { const normalizedAllowed = path.endsWith('/') && path.length > 1 ? path.slice(0, -1) : path; - return normalizedAllowed === targetPath || path === to.path; + const normalizedAllowedLower = normalizedAllowed.toLowerCase(); + const pathLower = path.toLowerCase(); + return normalizedAllowedLower === targetPathLower || pathLower === toPathLower; }); if (!isAllowed) { diff --git a/middleware/guest.ts b/middleware/guest.ts index ff7284b..77118e8 100644 --- a/middleware/guest.ts +++ b/middleware/guest.ts @@ -27,8 +27,9 @@ export default defineNuxtRouteMiddleware(async (to) => { try { console.log('🔍 Checking if user is already authenticated...'); + const headers = import.meta.server ? useRequestHeaders(['cookie']) as Record : {} // The $fetch will automatically send the new user_session cookie - const session = await $fetch<{ user: any } | null>('/api/auth/session').catch(() => null); + const session = await $fetch<{ user: any } | null>('/api/auth/session', { headers }).catch(() => null); if (session && session.user) { console.log('✅ User already authenticated, redirecting to dashboard'); diff --git a/pages/Anjungan/AnjunganCopy/[id].vue b/pages/Anjungan/AnjunganCopy/[id].vue new file mode 100644 index 0000000..823c2f9 --- /dev/null +++ b/pages/Anjungan/AnjunganCopy/[id].vue @@ -0,0 +1,2420 @@ + + + + + diff --git a/pages/Anjungan/AnjunganCopy/index.vue b/pages/Anjungan/AnjunganCopy/index.vue new file mode 100644 index 0000000..e162564 --- /dev/null +++ b/pages/Anjungan/AnjunganCopy/index.vue @@ -0,0 +1,387 @@ + + + + + + + diff --git a/stores/navItems1.ts b/stores/navItems1.ts index 51d988c..40aa629 100644 --- a/stores/navItems1.ts +++ b/stores/navItems1.ts @@ -36,6 +36,7 @@ const defaultNavItems: NavItem[] = [ path: "", children: [ { id: 10, name: "Anjungan", path: "/Anjungan/Anjungan", icon: "mdi-circle-small" }, + { id: 11, name: "Anjungan Eksekutif", path: "/anjungan/anjungancopy", icon: "mdi-circle-small" }, // { id: 11, name: "Klinik", path: "/Anjungan/AntrianKlinik", icon: "mdi-circle-small" }, { id: 12, name: "Klinik Ruang", path: "/Anjungan/AntrianKlinikRuang", icon: "mdi-circle-small"}, // { id: 13, name: "Penunjang", path: "/Anjungan/AntrianPenunjang", icon: "mdi-circle-small"}, @@ -63,7 +64,7 @@ const defaultNavItems: NavItem[] = [ }, ]; -const STORAGE_VERSION = '1.1'; // Increment this if you change structure or default paths +const STORAGE_VERSION = '1.3'; // Increment this if you change structure or default paths export const useNavItemsStore = defineStore('navItems', () => { const storedVersion = useLocalStorage('navItems_version', '0'); diff --git a/stores/queueStore.js b/stores/queueStore.js index 0b311e9..eb0be2d 100644 --- a/stores/queueStore.js +++ b/stores/queueStore.js @@ -2886,7 +2886,7 @@ const fetchPatientsForLoket = async (loketId, force = false) => { }; // Register patient from Anjungan (onsite registration) - const registerPatientFromAnjungan = (clinic, paymentType, visitType = 'SEKARANG', visitDate = null, shift = 'Shift 1', namaDokter = null, isFastTrack = false, fastTrackData = null, loketId = null, loket = null) => { + const registerPatientFromAnjungan = (clinic, paymentType, visitType = 'SEKARANG', visitDate = null, shift = 'Shift 1', namaDokter = null, isFastTrack = false, fastTrackData = null, loketId = null, loket = null, subSpesialis = null) => { // 1. Validasi keberadaan (prevent duplicates) // Gunakan date today untuk check-in sync const timestamp = new Date(); @@ -2946,6 +2946,9 @@ const fetchPatientsForLoket = async (loketId, force = false) => { calledByAdmin: false, penanggungJawab: (isFastTrack && fastTrackData) ? fastTrackData.penanggungJawab : null, alasanFastTrack: (isFastTrack && fastTrackData) ? fastTrackData.alasanFastTrack : null, + ruang: subSpesialis ? subSpesialis.namaRuang : null, + nomorRuang: subSpesialis ? subSpesialis.nomorRuang : null, + kodeRuang: subSpesialis ? subSpesialis.kodeRuang : null, }; // Auto-assign Loket ID if not provided, based on Clinic Mapping @@ -2977,7 +2980,7 @@ const fetchPatientsForLoket = async (loketId, force = false) => { * Register REGULER patient via API * POST to http://10.10.123.140:8089/api/v1/tiket/generate */ - const registerRegulerPatientViaApi = async (clinic, paymentType, visitType = 'SEKARANG', isFastTrack = false, fastTrackData = null) => { + const registerRegulerPatientViaApi = async (clinic, paymentType, visitType = 'SEKARANG', isFastTrack = false, fastTrackData = null, subSpesialis = null) => { try { // 1. Find appropriate idloket based on BOTH clinic code AND payment type const apiLoketsExist = loketStore.lokets?.some(l => l.source === 'api' || l.id < 1000); @@ -3101,7 +3104,10 @@ const fetchPatientsForLoket = async (loketId, force = false) => { alasanFastTrack: (isFastTrack && fastTrackData) ? fastTrackData.alasanFastTrack : null, // Additional API fields idvisit: 1, // Default menunggu - idtiket: apiData.id + idtiket: apiData.id, + ruang: subSpesialis ? subSpesialis.namaRuang : null, + nomorRuang: subSpesialis ? subSpesialis.nomorRuang : null, + kodeRuang: subSpesialis ? subSpesialis.kodeRuang : null, }; allPatients.value.push(newPatient);