Fix permissions handling with react context

Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
Émile Ré
2025-12-02 17:11:02 +04:00
parent accc8292b5
commit e65097f248
57 changed files with 609 additions and 840 deletions

View File

@@ -0,0 +1,17 @@
import { createContext } from "react";
import { Role } from "@probo/helpers";
export type PermissionsResponse = {
permissions: Record<string, Record<string, boolean>>;
role: Role;
};
type PermissionsContextType = {
isAuthorized: (entity: string, action: string) => boolean;
} & PermissionsResponse;
export const PermissionsContext = createContext<PermissionsContextType>({
permissions: {},
role: Role.VIEWER,
isAuthorized: () => false,
});

View File

@@ -1,27 +1,7 @@
import { useSuspenseQuery } from "@tanstack/react-query";
import { createContext, type PropsWithChildren } from "react";
import { type PropsWithChildren } from "react";
import { useOrganizationId } from "/hooks/useOrganizationId";
enum Role {
OWNER = "OWNER",
ADMIN = "ADMIN",
VIEWER = "VIEWER",
}
type PermissionsResponse = {
permissions: Record<string, Record<string, boolean>>;
role: Role;
};
type PermissionsContextType = {
isAuthorized: (entity: string, action: string) => boolean;
} & PermissionsResponse;
export const PermissionsContext = createContext<PermissionsContextType>({
permissions: {},
role: Role.VIEWER,
isAuthorized: () => false,
});
import { PermissionsContext, type PermissionsResponse } from "./PermissionsContext";
export function PermissionsProvider(props: PropsWithChildren) {
const { children } = props;