From 47400402022c5a90dda783f3f85131a12e28734c Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 9 Jul 2025 16:45:48 -0400 Subject: [PATCH] feat: Improve duplicate check logic in InterestDuplicateNotificationBanner with enhanced role verification and fallback handling --- .../InterestDuplicateNotificationBanner.vue | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/components/InterestDuplicateNotificationBanner.vue b/components/InterestDuplicateNotificationBanner.vue index 29c0374..b9e33d5 100644 --- a/components/InterestDuplicateNotificationBanner.vue +++ b/components/InterestDuplicateNotificationBanner.vue @@ -45,17 +45,29 @@ const loading = ref(false); const checkForDuplicates = async () => { if (loading.value) return; - // Only check for users with sales or admin role - const canViewDuplicates = await hasRole(['sales', 'admin']); - if (!canViewDuplicates) { - console.log('[InterestDuplicateNotification] User does not have sales/admin role'); - return; - } - console.log('[InterestDuplicateNotification] Checking for interest duplicates...'); try { loading.value = true; + + // Check roles with better error handling + let canViewDuplicates = false; + try { + canViewDuplicates = await hasRole(['sales', 'admin']); + console.log('[InterestDuplicateNotification] Role check result:', canViewDuplicates); + } catch (roleError) { + console.error('[InterestDuplicateNotification] Role check failed:', roleError); + // Try to get user info directly as fallback + const { isAdmin } = useAuthorization(); + canViewDuplicates = isAdmin(); + console.log('[InterestDuplicateNotification] Fallback admin check:', canViewDuplicates); + } + + if (!canViewDuplicates) { + console.log('[InterestDuplicateNotification] User does not have sales/admin role'); + return; + } + const response = await $fetch('/api/interests/duplicates/find', { method: 'GET', query: { @@ -92,6 +104,11 @@ onMounted(() => { // Always check for duplicates - remove session storage blocking for debugging console.log('[InterestDuplicateNotification] Component mounted, checking for duplicates...'); + // Clear any previous dismissal for debugging + if (process.client) { + sessionStorage.removeItem('interest-duplicates-banner-dismissed'); + } + // Check for duplicates for sales/admin users immediately checkForDuplicates(); });