Fix #8642 Session ID is not unique across users (#8660)

This commit is contained in:
Sachin Chaurasiya 2022-11-11 12:05:40 +05:30 committed by GitHub
parent 54808a027e
commit 2c430d1c7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 1 deletions

View File

@ -20,4 +20,6 @@ declare module '@analytics/session-utils' {
extra = {}, extra = {},
extend?: boolean extend?: boolean
) => Session; ) => Session;
export const removeSession: () => void;
} }

View File

@ -11,6 +11,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { removeSession } from '@analytics/session-utils';
import { Auth0Provider } from '@auth0/auth0-react'; import { Auth0Provider } from '@auth0/auth0-react';
import { Configuration } from '@azure/msal-browser'; import { Configuration } from '@azure/msal-browser';
import { MsalProvider } from '@azure/msal-react'; import { MsalProvider } from '@azure/msal-react';
@ -64,6 +65,7 @@ import {
getUserDataFromOidc, getUserDataFromOidc,
matchUserDetails, matchUserDetails,
} from '../../utils/UserDataUtils'; } from '../../utils/UserDataUtils';
import { resetWebAnalyticSession } from '../../utils/WebAnalyticsUtils';
import Auth0Authenticator from '../authenticators/Auth0Authenticator'; import Auth0Authenticator from '../authenticators/Auth0Authenticator';
import BasicAuthAuthenticator from '../authenticators/basic-auth.authenticator'; import BasicAuthAuthenticator from '../authenticators/basic-auth.authenticator';
import MsalAuthenticator from '../authenticators/MsalAuthenticator'; import MsalAuthenticator from '../authenticators/MsalAuthenticator';
@ -113,11 +115,16 @@ export const AuthProvider = ({
const onLoginHandler = () => { const onLoginHandler = () => {
setLoading(true); setLoading(true);
authenticatorRef.current?.invokeLogin(); authenticatorRef.current?.invokeLogin();
resetWebAnalyticSession();
}; };
const onLogoutHandler = useCallback(() => { const onLogoutHandler = useCallback(() => {
clearTimeout(timeoutId); clearTimeout(timeoutId);
authenticatorRef.current?.invokeLogout(); authenticatorRef.current?.invokeLogout();
// remove analytics session on logout
removeSession();
setLoading(false); setLoading(false);
}, [timeoutId]); }, [timeoutId]);

View File

@ -37,6 +37,7 @@ import {
showInfoToast, showInfoToast,
showSuccessToast, showSuccessToast,
} from '../../utils/ToastUtils'; } from '../../utils/ToastUtils';
import { resetWebAnalyticSession } from '../../utils/WebAnalyticsUtils';
import { useAuthContext } from './AuthProvider'; import { useAuthContext } from './AuthProvider';
import { OidcUser } from './AuthProvider.interface'; import { OidcUser } from './AuthProvider.interface';
@ -106,6 +107,9 @@ const BasicAuthProvider = ({
scope: '', scope: '',
}); });
} }
// reset web analytic session
resetWebAnalyticSession();
} catch (error) { } catch (error) {
const err = error as AxiosError<{ code: number; message: string }>; const err = error as AxiosError<{ code: number; message: string }>;

View File

@ -11,7 +11,11 @@
* limitations under the License. * 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 Analytics, { AnalyticsInstance } from 'analytics';
import { postPageView } from '../axiosAPIs/WebAnalyticsAPI'; import { postPageView } from '../axiosAPIs/WebAnalyticsAPI';
import { WebPageData } from '../components/WebAnalytics/WebAnalytics.interface'; 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);
};