Skip to content

Commit fa395eb

Browse files
committed
[E] Redirect to dashboard when entering admin from 403
1 parent abaec3b commit fa395eb

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

client/src/global/components/navigation/Primary.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ export default function NavigationPrimary(props) {
2222
});
2323
const pages = useFromStore({ path: `entityStore.entities.pages` });
2424
const texts = useFromStore({ path: `entityStore.entities.texts` });
25+
const fatalError = useFromStore({ path: "fatalError" });
2526

2627
const to = getDestinationPath({
2728
mode: props.mode,
2829
pathname,
29-
entities: { resources, resourceCollections, pages, texts }
30+
entities: { resources, resourceCollections, pages, texts },
31+
fatalError
3032
});
3133

3234
const authorization = new Authorization();

client/src/global/components/navigation/helpers.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ const extractIdentifier = (pathname, basePath) => {
108108
return identifier === "all" ? null : identifier;
109109
};
110110

111-
const getAdminPath = pathname => {
111+
const getAdminPath = (pathname, fatalError) => {
112+
if (fatalError && fatalError.type === "AUTHORIZATION")
113+
return "/backend/dashboard";
114+
112115
const routeKey = Object.keys(FE_ROUTE_MAP).find(key => {
113116
return FE_ROUTE_MAP[key]?.regex.test(pathname);
114117
});
@@ -184,7 +187,12 @@ const getFrontendPath = (pathname, entities) => {
184187
return `${route.link}/${identifier}`;
185188
};
186189

187-
export const getDestinationPath = ({ mode, pathname, entities }) => {
188-
if (mode === "frontend") return getAdminPath(pathname);
190+
export const getDestinationPath = ({
191+
mode,
192+
pathname,
193+
entities,
194+
fatalError
195+
}) => {
196+
if (mode === "frontend") return getAdminPath(pathname, fatalError);
189197
return getFrontendPath(pathname, entities);
190198
};

0 commit comments

Comments
 (0)