feat: Improve duplicate check logic in InterestDuplicateNotificationBanner with enhanced role verification and fallback handling
This commit is contained in:
parent
8f625c0df4
commit
4740040202
|
|
@ -45,17 +45,29 @@ const loading = ref(false);
|
||||||
const checkForDuplicates = async () => {
|
const checkForDuplicates = async () => {
|
||||||
if (loading.value) return;
|
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...');
|
console.log('[InterestDuplicateNotification] Checking for interest duplicates...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loading.value = true;
|
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', {
|
const response = await $fetch('/api/interests/duplicates/find', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
query: {
|
query: {
|
||||||
|
|
@ -92,6 +104,11 @@ onMounted(() => {
|
||||||
// Always check for duplicates - remove session storage blocking for debugging
|
// Always check for duplicates - remove session storage blocking for debugging
|
||||||
console.log('[InterestDuplicateNotification] Component mounted, checking for duplicates...');
|
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
|
// Check for duplicates for sales/admin users immediately
|
||||||
checkForDuplicates();
|
checkForDuplicates();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue