Skip to content

Commit 9836df0

Browse files
committed
feat(app-admin-users-cognito): make NotAuthorizedError composable
1 parent 1fd3165 commit 9836df0

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

packages/app-admin-users-cognito/src/createAuthentication/NotAuthorizedError/NotAuthorizedError.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as React from "react";
2+
import Helmet from "react-helmet";
23
import { css } from "emotion";
34
import styled from "@emotion/styled";
4-
import Helmet from "react-helmet";
5-
import authErrorImg from "./SecureRouteError.svg";
65
import { Typography } from "@webiny/ui/Typography";
76
import { useTenancy } from "@webiny/app-tenancy/hooks/useTenancy";
7+
import { useSecurity } from "@webiny/app-security";
8+
import { makeComposable } from "@webiny/app-admin";
9+
import authErrorImg from "./SecureRouteError.svg";
810

911
const ContentWrapper = styled("div")({
1012
display: "block",
@@ -31,18 +33,29 @@ const styles = {
3133
})
3234
};
3335

34-
export const NotAuthorizedError = () => {
36+
export interface ImageProps {
37+
className?: string;
38+
alt?: string;
39+
}
40+
41+
const Image = ({ className = styles.authErrorImgStyle, alt = "Not Authorized" }: ImageProps) => {
42+
return <img className={className} src={authErrorImg} alt={alt} />;
43+
};
44+
45+
const NotAuthorizedComponent = makeComposable("NotAuthorizedError", () => {
3546
const { setTenant } = useTenancy();
47+
const { identity } = useSecurity();
48+
49+
const defaultTenant = identity && identity.defaultTenant ? identity.defaultTenant.id : null;
3650

3751
const resetTenant = (): void => {
38-
setTenant(null);
52+
setTenant(defaultTenant);
3953
};
4054

4155
return (
4256
<ContentWrapper>
4357
<Helmet title={"Not authorized!"} />
44-
45-
<img className={styles.authErrorImgStyle} src={authErrorImg} alt="Not Authorized" />
58+
<Image />
4659

4760
<Typography use={"body1"} className={styles.bodyStyle}>
4861
You are not authorized to access this tenant!
@@ -57,4 +70,6 @@ export const NotAuthorizedError = () => {
5770
</a>
5871
</ContentWrapper>
5972
);
60-
};
73+
});
74+
75+
export const NotAuthorizedError = Object.assign(NotAuthorizedComponent, { Image });
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
export * from "./createAuthentication";
22
export * from "./createGetIdentityData";
33
export { Cognito } from "./Cognito";
4+
5+
import { NotAuthorizedError } from "./createAuthentication/NotAuthorizedError";
6+
7+
export const Components = {
8+
NotAuthorizedError
9+
};

0 commit comments

Comments
 (0)