Impersonate UI (#4243)
* Impersonate UI * Depracates Old admin required * Move permission container to features * Remove logic from dumb components * Fix export from v2 * Fix type cast - add tab filter * Redirect on authed pages * Add key back Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Omar López <[email protected]>
This commit is contained in:
5 files changed
+69
-21
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { useSession } from "next-auth/react";
|
||||
import { FC, Fragment } from "react";
|
||||
|
||||
import { UserPermissionRole } from ".prisma/client";
|
||||
|
||||
type AdminRequiredProps = {
|
||||
as?: keyof JSX.IntrinsicElements;
|
||||
children?: React.ReactNode;
|
||||
/**Not needed right now but will be useful if we ever expand our permission roles */
|
||||
roleRequired?: UserPermissionRole;
|
||||
};
|
||||
|
||||
export const PermissionContainer: FC<AdminRequiredProps> = ({
|
||||
children,
|
||||
as,
|
||||
roleRequired = "ADMIN",
|
||||
...rest
|
||||
}) => {
|
||||
const session = useSession();
|
||||
|
||||
// Admin can do everything
|
||||
if (session.data?.user.role !== roleRequired || !UserPermissionRole.ADMIN) return null;
|
||||
const Component = as ?? Fragment;
|
||||
return <Component {...rest}>{children}</Component>;
|
||||
};
|
||||
Reference in new issue
Block a user