Skip to content

Commit

Permalink
fix public page view
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Dec 10, 2024
1 parent 1a0591a commit 20cdcf1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/pages/reputation-score/[...score].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,4 @@ const ScorePage = () => {
);
};

export default withRoles(ScorePage, []);
export default withRoles(ScorePage);
11 changes: 10 additions & 1 deletion src/utils/withRoles.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import React, {
ComponentType,
FunctionComponent,
Expand All @@ -6,6 +8,8 @@ import React, {
} from 'react';
import { useRouter } from 'next/router';

import SimpleBackdrop from '@/components/global/LoadingBackdrop';

import useAppStore from '../store/useStore';

interface WithRolesProps {
Expand All @@ -21,7 +25,7 @@ interface ComponentWithLayout<P = {}> extends FunctionComponent<P> {

export function withRoles<P extends WithRolesProps>(
Component: ComponentWithLayout<P>,
requiredPermissions: string[]
requiredPermissions: string[] = []
): ComponentWithLayout<P> {
const WithRolesWrapper: ComponentWithLayout<P> = (props) => {
const userPermissions = useAppStore(
Expand All @@ -31,6 +35,11 @@ export function withRoles<P extends WithRolesProps>(
const router = useRouter();

useEffect(() => {
if (requiredPermissions.length === 0) {
setIsPermissionLoaded(true);
return;
}

const hasPermission = requiredPermissions.some((permission) =>
userPermissions.includes(permission)
);
Expand Down

0 comments on commit 20cdcf1

Please sign in to comment.