Skip to content

Commit

Permalink
Merge branch 'bugfix/ZKUI-189-clear-localstorage-when-logout' into q/1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bert-e committed Jun 17, 2022
2 parents 1956fc0 + ab57aa5 commit cce1dfc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/react/DataServiceRoleProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { createContext, useContext, useMemo } from 'react';
import { useParams } from 'react-router-dom';
import { generatePath, useHistory } from 'react-router';
import { regexArn, useAccounts } from './utils/hooks';
import { getRoleArnStored, setRoleArnStored } from './utils/localStorage';
import {
getRoleArnStored,
removeRoleArnStored,
setRoleArnStored,
} from './utils/localStorage';

export const _DataServiceRoleContext = createContext<null | {
role: { roleArn: string };
Expand All @@ -27,6 +31,19 @@ export const useCurrentAccount = () => {
? regexArn.exec(storedRoleArn).groups['account_id']
: '';
const accountsWithRoles = useAccounts();

// invalide the stored ARN if it's not in the list accountsWithRoles
useMemo(() => {
const isStoredArnValide = accountsWithRoles.find((account) => {
return account.Roles.find((role) => {
return role.Arn === storedRoleArn;
});
});
if (!isStoredArnValide && storedRoleArn && accountsWithRoles.length) {
removeRoleArnStored();
}
}, [storedRoleArn, JSON.stringify(accountsWithRoles)]);

const history = useHistory();
const account = useMemo(() => {
return accountsWithRoles.find((account) => {
Expand Down

0 comments on commit cce1dfc

Please sign in to comment.