Skip to content

Commit

Permalink
Update useEffect deps
Browse files Browse the repository at this point in the history
  • Loading branch information
tnorling committed Dec 15, 2020
1 parent 74e8d36 commit ef655f7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/msal-react/src/MsalProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function MsalProvider({instance, children}: MsalProviderProps): React.Rea
instance.removeEventCallback(callbackId);
}
};
}, [instance, accounts]);
}, [instance, accounts, logger]);

useEffect(() => {
const callbackId = instance.addEventCallback((message: EventMessage) => {
Expand Down Expand Up @@ -119,7 +119,7 @@ export function MsalProvider({instance, children}: MsalProviderProps): React.Rea
instance.removeEventCallback(callbackId);
}
};
}, [instance]);
}, [instance, logger]);

const contextValue: IMsalContext = {
instance,
Expand Down
7 changes: 1 addition & 6 deletions lib/msal-react/src/hooks/useAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,12 @@ function getAccount(instance: IPublicClientApplication, accountIdentifiers: Acco
}

export function useAccount(accountIdentifiers: AccountIdentifiers): AccountInfo | null {
const { instance, inProgress, logger } = useMsal();
const { instance, inProgress } = useMsal();

const [account, setAccount] = useState<AccountInfo|null>(null);

useEffect(() => {
setAccount(getAccount(instance, accountIdentifiers));
if (logger.isPiiLoggingEnabled()) {
logger.verbosePii(`useAccount - Account state set to ${account}`);
} else {
logger.verbose("useAccount - Account state set");
}
}, [inProgress, accountIdentifiers, instance]);

return account;
Expand Down
3 changes: 1 addition & 2 deletions lib/msal-react/src/hooks/useIsAuthenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ function isAuthenticated(allAccounts: AccountIdentifiers[], account: AccountInfo
}

export function useIsAuthenticated(matchAccount?: AccountIdentifiers): boolean {
const { accounts: allAccounts, logger } = useMsal();
const { accounts: allAccounts } = useMsal();
const account = useAccount(matchAccount || {});

const [hasAuthenticated, setHasAuthenticated] = useState<boolean>(false);

useEffect(() => {
setHasAuthenticated(isAuthenticated(allAccounts, account, matchAccount));
logger.verbose(`useIsAuthenticated - isAuthenticated state set to ${hasAuthenticated}`);
}, [allAccounts, account, matchAccount]);

return hasAuthenticated;
Expand Down
6 changes: 3 additions & 3 deletions lib/msal-react/src/hooks/useMsalAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function useMsalAuthentication(
default:
throw "Invalid interaction type provided.";
}
}, [instance, interactionType, authenticationRequest]);
}, [instance, interactionType, authenticationRequest, logger]);

useEffect(() => {
const callbackId = instance.addEventCallback((message: EventMessage) => {
Expand All @@ -70,7 +70,7 @@ export function useMsalAuthentication(
instance.removeEventCallback(callbackId);
}
};
}, [instance]);
}, [instance, logger]);

useEffect(() => {
if (!hasBeenCalled && !isAuthenticated && inProgress === InteractionStatus.None) {
Expand All @@ -82,7 +82,7 @@ export function useMsalAuthentication(
return;
});
}
}, [isAuthenticated, inProgress, hasBeenCalled, login]);
}, [isAuthenticated, inProgress, hasBeenCalled, login, logger]);

return { login, result, error };
}

0 comments on commit ef655f7

Please sign in to comment.