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 = {},
extend?: boolean
) => Session;
export const removeSession: () => void;
}

View File

@ -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]);

View File

@ -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 }>;

View File

@ -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);
};