diff --git a/src/komponenter/header/Header.tsx b/src/komponenter/header/Header.tsx index 7f498a1ef..d40b8073e 100644 --- a/src/komponenter/header/Header.tsx +++ b/src/komponenter/header/Header.tsx @@ -97,7 +97,9 @@ export const Header = () => { } }, [menypunkt]); - useLoadIfActiveSession(); + useLoadIfActiveSession({ + userState: cookies['psCurrentState'] + }); // Handle enforced login useEffect(() => { diff --git a/src/utils/hooks/useScreenSharing.ts b/src/utils/hooks/useScreenSharing.ts index fab9ccd91..a3edcccd6 100644 --- a/src/utils/hooks/useScreenSharing.ts +++ b/src/utils/hooks/useScreenSharing.ts @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react'; -import { VNGAGE_ID, VngageUserState, vendorScripts } from 'komponenter/header/vendorScripts'; +import { vendorScripts } from 'komponenter/header/vendorScripts'; import { loadExternalScript } from 'utils/external-scripts'; type UseScreenSharingOptions = { @@ -45,13 +45,10 @@ export function useScreenSharing({ enabled }: UseScreenSharingOptions): UseScree }; } -export function useLoadIfActiveSession() { +export function useLoadIfActiveSession({ userState }: { userState: string | undefined }) { useEffect(() => { - const userState = localStorage.getItem(`vngage_${VNGAGE_ID.toLowerCase()}`); - const parsedUserState = userState ? (JSON.parse(userState) as VngageUserState) : undefined; - - if (parsedUserState && parsedUserState.user.state !== 'Ready') { + if (userState && userState !== 'Ready') { loadExternalScript(vendorScripts.skjermdeling); } - }, []); + }, [userState]); }