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

Curry funciton to accept roles before creating component.

parent 57c1002f
No related branches found
No related tags found
2 merge requests!56Refined auth flow and new website pages.,!53Feature/authorization/curry
......@@ -25,15 +25,16 @@ interface WithAuthProps {
* This creates a "personal area" in the working implementation.
* @returns {FC<T>} wrapped component.
*/
export const withAuthorization = <T extends WithAuthProps = WithAuthProps>(
export const withAuthorization = (allowedRoles: string[]) => <
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, isAuth } = useContext(AuthContext);
console.log(`ROLE ${role} AUTH ${isAuth}`);
......
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