Skip to content

Commit 39f42bc

Browse files
authored
feat: show dialog with a redirect if permissions are required (#16661)
Closes [this issue](coder/internal#385 (comment)) ## New behavior When a user ends up on a page they don't have permission to view instead of being redirected back to _/workspaces_ they'll be met with the un-closeable dialog below with a link to _/workspaces_. This is similar to [this PR](#16644) but IMO we should be making sure we are using `<RequirePermissions />` wherever applicable and only relying on `<ErrorAlert />` as a fallback in case there is some page we missed or endpoint we're accidentally using. ![Screenshot 2025-02-21 at 4 50 58 PM](https://github.com/user-attachments/assets/1f986e28-d99b-425d-b67a-80bb08d5111f)
1 parent ce49ce4 commit 39f42bc

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

site/src/contexts/auth/RequirePermission.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
import {
2+
Dialog,
3+
DialogContent,
4+
DialogDescription,
5+
DialogFooter,
6+
DialogHeader,
7+
DialogTitle,
8+
} from "components/Dialog/Dialog";
9+
import { Link } from "components/Link/Link";
110
import type { FC, ReactNode } from "react";
2-
import { Navigate } from "react-router-dom";
311

412
export interface RequirePermissionProps {
513
children?: ReactNode;
@@ -14,7 +22,24 @@ export const RequirePermission: FC<RequirePermissionProps> = ({
1422
isFeatureVisible,
1523
}) => {
1624
if (!isFeatureVisible) {
17-
return <Navigate to="/workspaces" />;
25+
return (
26+
<Dialog open={true}>
27+
<DialogContent>
28+
<DialogHeader>
29+
<DialogTitle>
30+
You don't have permission to view this page
31+
</DialogTitle>
32+
</DialogHeader>
33+
<DialogDescription>
34+
If you believe this is a mistake, please contact your administrator
35+
or try signing in with different credentials.
36+
</DialogDescription>
37+
<DialogFooter>
38+
<Link href="/">Go to workspaces</Link>
39+
</DialogFooter>
40+
</DialogContent>
41+
</Dialog>
42+
);
1843
}
1944

2045
return <>{children}</>;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy