diff --git a/openmetadata-ui/src/main/resources/ui/src/@types/web-analytics.d.ts b/openmetadata-ui/src/main/resources/ui/src/@types/web-analytics.d.ts index 8c30a67270b..9e54343c428 100644 --- a/openmetadata-ui/src/main/resources/ui/src/@types/web-analytics.d.ts +++ b/openmetadata-ui/src/main/resources/ui/src/@types/web-analytics.d.ts @@ -20,4 +20,6 @@ declare module '@analytics/session-utils' { extra = {}, extend?: boolean ) => Session; + + export const removeSession: () => void; } diff --git a/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/AuthProvider.tsx b/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/AuthProvider.tsx index af3a7f0dc1c..0f3efc87f79 100644 --- a/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/AuthProvider.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/AuthProvider.tsx @@ -11,6 +11,7 @@ * limitations under the License. */ +import { removeSession } from '@analytics/session-utils'; import { Auth0Provider } from '@auth0/auth0-react'; import { Configuration } from '@azure/msal-browser'; import { MsalProvider } from '@azure/msal-react'; @@ -64,6 +65,7 @@ import { getUserDataFromOidc, matchUserDetails, } from '../../utils/UserDataUtils'; +import { resetWebAnalyticSession } from '../../utils/WebAnalyticsUtils'; import Auth0Authenticator from '../authenticators/Auth0Authenticator'; import BasicAuthAuthenticator from '../authenticators/basic-auth.authenticator'; import MsalAuthenticator from '../authenticators/MsalAuthenticator'; @@ -113,11 +115,16 @@ export const AuthProvider = ({ const onLoginHandler = () => { setLoading(true); authenticatorRef.current?.invokeLogin(); + + resetWebAnalyticSession(); }; const onLogoutHandler = useCallback(() => { clearTimeout(timeoutId); authenticatorRef.current?.invokeLogout(); + + // remove analytics session on logout + removeSession(); setLoading(false); }, [timeoutId]); diff --git a/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/basic-auth.provider.tsx b/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/basic-auth.provider.tsx index 4d8e04faf75..1d18e4e1bf7 100644 --- a/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/basic-auth.provider.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/authentication/auth-provider/basic-auth.provider.tsx @@ -37,6 +37,7 @@ import { showInfoToast, showSuccessToast, } from '../../utils/ToastUtils'; +import { resetWebAnalyticSession } from '../../utils/WebAnalyticsUtils'; import { useAuthContext } from './AuthProvider'; import { OidcUser } from './AuthProvider.interface'; @@ -106,6 +107,9 @@ const BasicAuthProvider = ({ scope: '', }); } + + // reset web analytic session + resetWebAnalyticSession(); } catch (error) { const err = error as AxiosError<{ code: number; message: string }>; diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/WebAnalyticsUtils.ts b/openmetadata-ui/src/main/resources/ui/src/utils/WebAnalyticsUtils.ts index f3f69e7ce61..be9da47ee2b 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/WebAnalyticsUtils.ts +++ b/openmetadata-ui/src/main/resources/ui/src/utils/WebAnalyticsUtils.ts @@ -11,7 +11,11 @@ * limitations under the License. */ -import { getSession, setSession } from '@analytics/session-utils'; +import { + getSession, + removeSession, + setSession, +} from '@analytics/session-utils'; import Analytics, { AnalyticsInstance } from 'analytics'; import { postPageView } from '../axiosAPIs/WebAnalyticsAPI'; import { WebPageData } from '../components/WebAnalytics/WebAnalytics.interface'; @@ -130,3 +134,11 @@ export const getAnalyticInstance = (userId: string): AnalyticsInstance => { ], }); }; + +export const resetWebAnalyticSession = () => { + // remove existing session first + removeSession(); + + // then set new analytics session for 30 minutes + setSession(30); +};