Skip to content

Commit 1517ab6

Browse files
committed
feat: enhance Authorized component to accept role prop for group-based access control
1 parent 9ca404c commit 1517ab6

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/Components/Auth/With.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import { useAuth } from "react-oidc-context";
44
/**
55
* @author Aloento
66
* @since 1.0.0
7-
* @version 0.1.0
7+
* @version 0.2.0
88
*/
9-
export function Authorized({ children }: { children: ReactNode }): ReactNode {
9+
export function Authorized({ children, role }: { children: ReactNode, role?: string }): ReactNode {
1010
const auth = useAuth();
1111

1212
if (auth.isAuthenticated || process.env.NODE_ENV === "development") {
13+
if (role && !((auth.user?.profile as any)?.groups as string[])?.includes(role)) {
14+
return null;
15+
}
1316
return children;
1417
}
1518

src/Components/Layout/MobileMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Authorized } from "../Auth/With";
55
/**
66
* @author Aloento
77
* @since 1.0.0
8-
* @version 0.1.0
8+
* @version 0.2.0
99
*/
1010
export function MobileMenu() {
1111
const auth = useAuth();

src/Components/Layout/ProfileMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useAuth } from "react-oidc-context";
44
/**
55
* @author Aloento
66
* @since 1.0.0
7-
* @version 0.1.0
7+
* @version 0.2.0
88
*/
99
export function ProfileMenu() {
1010
const auth = useAuth();

0 commit comments

Comments
 (0)