Skip to content

Commit

Permalink
fix(app-admin-users-cognito): don't render permissions error in syste…
Browse files Browse the repository at this point in the history
…m installer
  • Loading branch information
Pavel910 committed Oct 19, 2023
1 parent cc23cbd commit 4442db5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import {
createAuthentication as baseCreateAuthentication,
AuthenticationFactoryConfig as BaseConfig
} from "@webiny/app-admin-cognito";
import { useTags } from "@webiny/app-admin";
import { useTenancy, withTenant } from "@webiny/app-tenancy";
import { NotAuthorizedError } from "./NotAuthorizedError";
import { createGetIdentityData, LOGIN_ST, LOGIN_MT } from "~/createGetIdentityData";
import { useTenancy, withTenant } from "@webiny/app-tenancy";
import { GetIdentityDataCallable } from "~/createGetIdentityData/createGetIdentityData";

export interface CreateAuthenticationConfig extends Partial<BaseConfig> {
Expand Down Expand Up @@ -42,6 +43,7 @@ export const createAuthentication = (config: CreateAuthenticationConfig = {}) =>
};

const Authentication: React.FC<AuthenticationProps> = ({ getIdentityData, children }) => {
const { installer } = useTags();
const [error, setError] = useState<string | null>(null);
const BaseAuthentication = useMemo(() => {
return baseCreateAuthentication({
Expand All @@ -53,7 +55,7 @@ export const createAuthentication = (config: CreateAuthenticationConfig = {}) =>
});
}, []);

if (error) {
if (error && !installer) {
return <NotAuthorizedError />;
}

Expand Down
8 changes: 7 additions & 1 deletion packages/app-admin/src/base/ui/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ interface TagsProps {
}

export const Tags: React.FC<TagsProps> = ({ tags, children }) => {
return <TagsContext.Provider value={tags}>{children}</TagsContext.Provider>;
const parentContext = useContext(TagsContext);

return (
<TagsContext.Provider value={{ ...parentContext, ...tags }}>
{children}
</TagsContext.Provider>
);
};

export const useTags = () => {
Expand Down
30 changes: 16 additions & 14 deletions packages/app-admin/src/components/AppInstaller/AppInstaller.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { default as localStorage } from "store";
import { LoginScreen } from "~/index";
import { LoginScreen, Tags } from "~/index";
import { useSecurity } from "@webiny/app-security";
import { CircularProgress } from "@webiny/ui/Progress";
import { ButtonPrimary } from "@webiny/ui/Button";
Expand Down Expand Up @@ -55,19 +55,21 @@ export const AppInstaller: React.FC = ({ children }) => {

const renderLayout = (content: React.ReactNode, secure = false): React.ReactElement => {
return (
<SplitView className={installerSplitView}>
<LeftPanel span={2}>
<Sidebar
allInstallers={installers}
installer={installer}
showLogin={showLogin}
/>
</LeftPanel>
<RightPanel span={10}>
{!showLogin && !secure && content}
{(showLogin || secure) && <LoginScreen>{content}</LoginScreen>}
</RightPanel>
</SplitView>
<Tags tags={{ installer: true }}>
<SplitView className={installerSplitView}>
<LeftPanel span={2}>
<Sidebar
allInstallers={installers}
installer={installer}
showLogin={showLogin}
/>
</LeftPanel>
<RightPanel span={10}>
{!showLogin && !secure && content}
{(showLogin || secure) && <LoginScreen>{content}</LoginScreen>}
</RightPanel>
</SplitView>
</Tags>
);
};

Expand Down

0 comments on commit 4442db5

Please sign in to comment.