Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1490 from navikt/cookies-skjermdeling-lazyload
Browse files Browse the repository at this point in the history
Use cookies instead of localStorage to check screensharing user state
  • Loading branch information
max-nav authored Sep 13, 2023
2 parents d2bc244 + c20fcbd commit 0298a0d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/komponenter/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export const Header = () => {
}
}, [menypunkt]);

useLoadIfActiveSession();
useLoadIfActiveSession({
userState: cookies['psCurrentState']
});

// Handle enforced login
useEffect(() => {
Expand Down
11 changes: 4 additions & 7 deletions src/utils/hooks/useScreenSharing.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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]);
}

0 comments on commit 0298a0d

Please sign in to comment.