Skip to content

Commit

Permalink
feat✨: add withAuthentication HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
eternallycyf committed Apr 23, 2023
1 parent 9693034 commit bf2ee64
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/Enhance/withAuthentication.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

interface Props {
[key: string]: any;
}

interface ComponentWithAuthProps extends Props {
isAuth: boolean;
}

export default function withAuthentication<P extends Props>(
Component: React.ComponentType<P>,
): React.FC<ComponentWithAuthProps & P> {
return function AuthenticatedComponent(props: ComponentWithAuthProps & P) {
const { isAuth, ...rest } = props;

if (isAuth) {
return <Component {...(rest as P)} />;
} else {
return <div className="error">no Auth</div>;
}
};
}

0 comments on commit bf2ee64

Please sign in to comment.