Skip to content

Commit

Permalink
fix: "not authorised" page style (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloks98 committed Oct 9, 2020
1 parent f83dd0c commit d56aa5a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions packages/app-security/src/admin/plugins/secureRouteError.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import * as React from "react";
import { Plugin } from "@webiny/plugins/types";
import Helmet from "react-helmet";
import NotAuthorizedError from "@webiny/app-security/components/NotAuthorizedError";

type SecureRouteErrorPlugin = Plugin & { render: () => React.ReactNode };

const plugin: SecureRouteErrorPlugin = {
type: "secure-route-error",
name: "secure-route-error",
render() {
return (
<>
<Helmet title={"Not authorized"} />
<span>You are not authorized to access this route.</span>
</>
);
return <NotAuthorizedError />;
}
};

Expand Down
55 changes: 55 additions & 0 deletions packages/app-security/src/components/NotAuthorizedError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as React from "react";
import { Link } from "@webiny/react-router";
import { css } from "emotion";
import styled from "@emotion/styled";
import Helmet from "react-helmet";
import authErrorImg from "../admin/assets/images/SecureRouteError.svg";
import { Typography } from "@webiny/ui/Typography";

const ContentWrapper = styled("div")({
display: "block",
paddingTop: "15%",
textAlign: "center",
margin: "auto"
});

const styles = {
authErrorImgStyle: css({
width: "192px",
paddingBottom: "24px"
}),
bodyStyle: css({
color: "var(--mdc-theme-text-primary-on-background)",
display: "block"
}),
linkStyle: css({
textDecoration: "none",
"&:hover": {
textDecoration: "none"
}
})
};

const NotAuthorizedError = () => {
return (
<ContentWrapper>
<Helmet title={"Not authorized"} />

<img className={styles.authErrorImgStyle} src={authErrorImg} alt="Not Authorized" />

<Typography use={"body1"} className={styles.bodyStyle}>
You are not authorized to view this route.
</Typography>

<Typography use={"body1"} className={styles.bodyStyle}>
Please contact your administrator to request access.
</Typography>

<Link to="/" className={styles.linkStyle}>
Take me back.
</Link>
</ContentWrapper>
);
};

export default NotAuthorizedError;
3 changes: 2 additions & 1 deletion packages/app-security/src/components/SecureRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { hasScopes } from "@webiny/app-security";
import { getPlugin } from "@webiny/plugins";
import { ResourcesType } from "../identity";
import { SecureRouteErrorPlugin } from "@webiny/app-security/types";
import NotAuthorizedError from "@webiny/app-security/components/NotAuthorizedError";

export default ({
children,
Expand All @@ -19,7 +20,7 @@ export default ({

const plugin = getPlugin<SecureRouteErrorPlugin>("secure-route-error");
if (!plugin) {
return <span>You are not authorized to view this route.</span>;
return <NotAuthorizedError />;
}
return plugin.render();
};

0 comments on commit d56aa5a

Please sign in to comment.