Skip to content

Commit

Permalink
Fix SatelliteToken org admin check to handle if user info is not yet …
Browse files Browse the repository at this point in the history
…loaded
  • Loading branch information
florkbr committed Sep 13, 2024
1 parent 3e365d1 commit 0bf8ad8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/layouts/SatelliteToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ import { Page, PageSection } from '@patternfly/react-core/dist/dynamic/component
import SatelliteTable from '../components/Satellite/SatelliteTable';
import IPWhitelistTable from '../components/Satellite/IPWhitelistTable';
import { getEnv } from '../utils/common';
import ChromeAuthContext from '../auth/ChromeAuthContext';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';
import NotFoundRoute from '../components/NotFoundRoute';

const SatelliteToken: React.FC = () => {
const [token, setToken] = useState('');
const [error, setError] = useState(null);
const { user } = useContext(ChromeAuthContext);
const [isOrgAdmin, setIsOrgAdmin] = useState<boolean>(false);
const { auth } = useChrome();
const isITLess = useFlag('platform.chrome.itless');

if (!isITLess) {
return <NotFoundRoute />;
}

useEffect(() => {
auth.getUser().then((user) => user && setIsOrgAdmin(!!user?.identity?.user?.is_org_admin));
}, []);

const generateToken = () => {
axios
.get('/api/identity/certificate/token')
Expand Down Expand Up @@ -90,7 +95,7 @@ const SatelliteToken: React.FC = () => {
</CardBody>
</Card>
</PageSection>
{user.identity.user?.is_org_admin ? (
{isOrgAdmin ? (
<PageSection>
<Card>
<CardTitle>IP Address Allow List</CardTitle>
Expand Down

0 comments on commit 0bf8ad8

Please sign in to comment.