From 4102d0f463fa6e9612c9043e8fb6fb24cfd60709 Mon Sep 17 00:00:00 2001 From: heheer Date: Wed, 24 Dec 2025 14:42:22 +0800 Subject: [PATCH] fix clear token --- .../support/activity/ActivityAdModal.tsx | 9 +++++--- projects/app/src/web/support/user/auth.ts | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/projects/app/src/components/support/activity/ActivityAdModal.tsx b/projects/app/src/components/support/activity/ActivityAdModal.tsx index 15d35b8cc..63849bbb9 100644 --- a/projects/app/src/components/support/activity/ActivityAdModal.tsx +++ b/projects/app/src/components/support/activity/ActivityAdModal.tsx @@ -27,11 +27,13 @@ const ActivityAdModal = () => { const router = useRouter(); // Check if ad was recently closed - const [closedData, setClosedData] = useLocalStorageState(CLOSED_AD_KEY); + const [closedData, setClosedData] = useLocalStorageState(CLOSED_AD_KEY, { + listenStorageChange: true + }); const { data } = useRequest2( async () => { - if (!feConfigs?.isPlus) return; + if (!feConfigs?.isPlus || !userInfo) return; return getActivityAd(); }, { @@ -59,7 +61,8 @@ const ActivityAdModal = () => { if (res?.activityAdImage && shouldShowAd) { onOpen(); } - } + }, + refreshDeps: [userInfo] } ); diff --git a/projects/app/src/web/support/user/auth.ts b/projects/app/src/web/support/user/auth.ts index 165262ac8..688f656b9 100644 --- a/projects/app/src/web/support/user/auth.ts +++ b/projects/app/src/web/support/user/auth.ts @@ -11,6 +11,29 @@ const clearOperationalAdStorage = () => { console.error('Failed to clear operational ad storage:', error); } }; +const clearActivityAdStorage = () => { + try { + const key = 'activity_ad_closed'; + const oldValue = localStorage.getItem(key); + localStorage.removeItem(key); + + // Dispatch ahooks sync event to update useLocalStorageState + if (oldValue !== null) { + window.dispatchEvent( + new CustomEvent('AHOOKS_SYNC_STORAGE_EVENT_NAME', { + detail: { + key, + newValue: null, + oldValue, + storageArea: localStorage + } + }) + ); + } + } catch (error) { + console.error('Failed to clear activity ad storage:', error); + } +}; export const clearToken = () => { try {