Merge branch 'develop' of https://github.com/IMPHNEN/imphnen-frontend-service into develop
This commit is contained in:
@@ -1,18 +1,10 @@
|
|||||||
import { lazy, LazyExoticComponent, ReactNode } from 'react';
|
import { lazy, LazyExoticComponent, ReactNode } from 'react';
|
||||||
import { ActionFunction, LoaderFunction, RouteObject } from 'react-router';
|
import { ActionFunction, LoaderFunction, RouteObject } from 'react-router';
|
||||||
|
|
||||||
type TPermissionItem = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
created_at: string;
|
|
||||||
updated_at: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
interface PageModuleExports {
|
interface PageModuleExports {
|
||||||
default: () => ReactNode;
|
default: () => ReactNode;
|
||||||
loader?: LoaderFunction;
|
loader?: LoaderFunction;
|
||||||
action?: ActionFunction;
|
action?: ActionFunction;
|
||||||
permissions?: Array<string>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LoadingModuleExports {
|
interface LoadingModuleExports {
|
||||||
@@ -58,18 +50,8 @@ export function convertPagesToRoute(
|
|||||||
return 'loader' in result ? result.loader?.(args) : null;
|
return 'loader' in result ? result.loader?.(args) : null;
|
||||||
},
|
},
|
||||||
async guard() {
|
async guard() {
|
||||||
const result = (await importer()) as PageModuleExports;
|
// Permission checking removed - always allow access
|
||||||
const localStoragePermission = localStorage.getItem('permissions');
|
return true;
|
||||||
const permissions: TPermissionItem[] | undefined =
|
|
||||||
localStoragePermission
|
|
||||||
? JSON.parse(localStoragePermission)
|
|
||||||
: undefined;
|
|
||||||
return 'permissions' in result
|
|
||||||
? result.permissions?.every(
|
|
||||||
(permission) =>
|
|
||||||
permissions?.some((item) => permission === item.name) || false
|
|
||||||
) || false
|
|
||||||
: true;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
routes = mergeRoutes(routes, route);
|
routes = mergeRoutes(routes, route);
|
||||||
|
|||||||
@@ -1,27 +1,11 @@
|
|||||||
import { FC, PropsWithChildren, ReactNode, useMemo } from 'react';
|
import { FC, PropsWithChildren, ReactNode } from 'react';
|
||||||
import { useSession } from '../../hooks/use-session';
|
|
||||||
|
|
||||||
type TProps = PropsWithChildren<{
|
type TProps = PropsWithChildren<{
|
||||||
permissions: Array<string>;
|
permissions?: Array<string>;
|
||||||
fallback?: ReactNode;
|
fallback?: ReactNode;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const Guard: FC<TProps> = (props): ReactNode => {
|
export const Guard: FC<TProps> = (props): ReactNode => {
|
||||||
const { session } = useSession();
|
// Permission checking removed - always allow access
|
||||||
|
return props.children;
|
||||||
const permissionKeys = useMemo(() => {
|
|
||||||
return session?.user?.role?.permissions.map((perm) => perm.name) ?? [];
|
|
||||||
}, [session?.user?.role]);
|
|
||||||
|
|
||||||
const allowed = useMemo(() => {
|
|
||||||
return props.permissions.every((permission) =>
|
|
||||||
permissionKeys.includes(permission)
|
|
||||||
);
|
|
||||||
}, [permissionKeys, props.permissions]);
|
|
||||||
|
|
||||||
if (allowed) {
|
|
||||||
return props.children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return props.fallback ?? null;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user