Skip to content

Commit

Permalink
all paths outside locked tenant are Not Found (including valid tenants)
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Apr 14, 2021
1 parent 980159b commit 75c4a0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions spotlight-client/src/PageHome/PageHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const PageHome = (): React.ReactElement => {
if (locked && currentTenantId) {
return (
<Redirect
noThrow
to={getUrlForResource({
page: "tenant",
params: { tenantId: currentTenantId },
Expand Down
13 changes: 11 additions & 2 deletions spotlight-client/src/withRouteSync/withRouteSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { RouteComponentProps } from "@reach/router";
import { action } from "mobx";
import { observer } from "mobx-react-lite";
import React, { ComponentType, useEffect } from "react";
import NotFound from "../NotFound";
import normalizeRouteParams from "../routerUtils/normalizeRouteParams";
Expand All @@ -40,9 +41,17 @@ const withRouteSync = <Props extends RouteComponentProps & RouteParams>(

const { path } = props;

const isTenantForbidden =
tenantStore.locked &&
// we're checking for wrong Tenants, not no Tenant
normalizedProps.tenantId &&
tenantStore.currentTenantId !== normalizedProps.tenantId;

const isRouteInvalid =
isTenantForbidden ||
Object.values(normalizedProps).includes(null) ||
// catchall path for partially valid URLs; e.g. :tenantId/something-invalid
Object.values(normalizedProps).includes(null) || path === "/*";
path === "/*";

// this is fine, we actually want this to run on every render
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -69,7 +78,7 @@ const withRouteSync = <Props extends RouteComponentProps & RouteParams>(
);
};

return WrappedRouteComponent;
return observer(WrappedRouteComponent);
};

export default withRouteSync;

0 comments on commit 75c4a0f

Please sign in to comment.