Skip to content
Snippets Groups Projects
Commit bb875367 authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Merge branch 'fix/authorization' into 'dev'

Set up HCO.

See merge request !49
parents dab30cb2 4330fb23
No related branches found
No related tags found
2 merge requests!56Refined auth flow and new website pages.,!49Set up HCO.
Pipeline #12358 passed
import { Unauthorized } from 'components/NonAuthUser/Unauthorized/Unauthorized';
import React, { ComponentType, FC } from 'react';
interface WithAuthProps {
allowedRoles: string[];
}
interface Props extends WithAuthProps {
children: React.ReactNode;
}
/* eslint-disable react/jsx-props-no-spreading */
/**
*
* @param WrappedComponent component to be wrapped by the authentication control.
* This creates a "personal area" in the working implementation.
* @returns {FC<T>} wrapped component.
*/
export const withAuthorization = <T extends WithAuthProps = WithAuthProps>(
WrappedComponent: React.ComponentType<T>,
): FC<T> => {
// Creating the inner component. The calculated Props type here is the where the magic happens.
const ComponentWithAuthorization: FC<T> = (
props: Omit<T, keyof WithAuthProps>,
) => {
const { allowedRoles } = props as T;
const role = 'admin';
const isAuth = true;
// props comes afterwards so the can override the default ones.
return allowedRoles.includes(role) && isAuth ? (
<WrappedComponent {...(props as T)} />
) : (
<Unauthorized />
);
};
return ComponentWithAuthorization;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment