Skip to content

Commit

Permalink
DEVPROD-7675: Avoid exposing /login route in non-development builds (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
minnakt authored Jun 24, 2024
1 parent a5ae110 commit ce9219e
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 13 deletions.
5 changes: 4 additions & 1 deletion apps/parsley/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import routes from "constants/routes";
import { GlobalProviders } from "context";
import Content from "pages";
import { Login } from "pages/Login";
import { isDevelopmentBuild } from "utils/environmentVariables";

const App = () => (
<ErrorBoundary>
Expand All @@ -14,7 +15,9 @@ const App = () => (
<GlobalProviders>
<AppWrapper>
<Routes>
<Route element={<Login />} path={routes.login} />
{isDevelopmentBuild() && (
<Route element={<Login />} path={routes.login} />
)}
<Route element={<Content />} path="/*" />
</Routes>
</AppWrapper>
Expand Down
5 changes: 4 additions & 1 deletion apps/spruce/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import { routes } from "constants/routes";
import { ContextProviders } from "context/Providers";
import GQLWrapper from "gql/GQLWrapper";
import { Login } from "pages/Login";
import { isDevelopmentBuild, isLocal } from "utils/environmentVariables";

const browserRouter = createBrowserRouter(
createRoutesFromElements(
<>
<Route path={routes.login} element={<Login />} />
{(isDevelopmentBuild() || isLocal()) && (
<Route path={routes.login} element={<Login />} />
)}
<Route
path="/*"
element={
Expand Down
2 changes: 1 addition & 1 deletion apps/spruce/src/components/styles/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const PageWrapper = styled.div`
padding: ${size.m} ${size.l};
`;

export const PageGrid = styled.section`
export const PageGrid = styled.div`
display: grid;
grid-template-areas:
"header header"
Expand Down
10 changes: 5 additions & 5 deletions apps/spruce/src/pages/404/NotFound.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { CustomStoryObj, CustomMeta } from "test_utils/types";

import NotFound from "./NotFound";
import NotFoundSvg from "./NotFoundSvg";

export default {
component: NotFound,
} satisfies CustomMeta<typeof NotFound>;
component: NotFoundSvg,
} satisfies CustomMeta<typeof NotFoundSvg>;

export const Default404: CustomStoryObj<typeof NotFound> = {
export const Default404: CustomStoryObj<typeof NotFoundSvg> = {
render: () => (
<div style={{ height: "100%", width: "100%" }}>
<NotFound />
<NotFoundSvg />
</div>
),
};
10 changes: 7 additions & 3 deletions apps/spruce/src/pages/404/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import notFound from "./notFound.svg";
import { Suspense, lazy } from "react";

const NotFound = () => (
<img src={notFound} alt="Page not found" data-cy="404" />
const NotFoundSvg = lazy(() => import("./NotFoundSvg"));

const NotFound: React.FC = () => (
<Suspense fallback={<div>Loading</div>}>
<NotFoundSvg />
</Suspense>
);

export default NotFound;
13 changes: 13 additions & 0 deletions apps/spruce/src/pages/404/NotFoundSvg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import notFound from "./notFound.svg";

// It's not possible to lazy load an SVG, so we wrap the SVG in a React component.
const NotFoundSvg: React.FC = () => (
<img
alt="Page not found"
data-cy="404"
src={notFound}
style={{ height: "inherit", width: "100%", objectFit: "cover" }}
/>
);

export default NotFoundSvg;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
alt="Page not found"
data-cy="404"
src="/src/pages/404/notFound.svg"
style="height: inherit; width: 100%; object-fit: cover;"
/>
</div>
</div>
6 changes: 6 additions & 0 deletions apps/spruce/src/utils/environmentVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export const isDevelopmentBuild: () => boolean = () =>
export const isProductionBuild = (): boolean =>
process.env.NODE_ENV === "production";

/**
* `isLocal()` indicates if the current build is a local build.
* @returns `true` if the current build is a local build.
*/
export const isLocal = () => getReleaseStage() === "local";

/**
* `isBeta()` indicates if the current build is a build meant for a beta deployment.
* @returns `true` if the current build is a beta build.
Expand Down
3 changes: 1 addition & 2 deletions apps/spruce/src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { routes } from "constants/routes";
import { getUiUrl } from "./environmentVariables";
import { reportError } from "./errorReporting";

export const shouldLogoutAndRedirect = (statusCode: number) =>
statusCode === 401 && window.location.pathname !== routes.login;
statusCode === 401;

export const post = async (url: string, body: unknown) => {
try {
Expand Down

0 comments on commit ce9219e

Please sign in to comment.