Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temporary open for tester off #133

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/admin/src/components/LayoutHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const Header = () => {
className="text-base text-center text-white-A700 w-auto"
size="txtLexendSemiBold16WhiteA700"
>
<Link href={AdminPaths.CAMPAIGNS}>Dashboard</Link>
<Link href={AdminPaths.DASHBOARD}>Dashboard</Link>
</Text>
</div>
</div>
Expand Down
20 changes: 10 additions & 10 deletions packages/admin/src/hocs/RouterGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect, useCallback } from 'react';
import { useAccount } from '@casperdash/usewallet';
import { AdminPaths, PublicPaths } from '@mlem-admin/enums/paths.enum';
import { checkUser, setUserInfo } from '@mlem-admin/services/auth';
// import { isAdmin } from '@mlem-admin/utils/permission';
import { isAdmin } from '@mlem-admin/utils/permission';
import { useRouter } from 'next/router';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -43,22 +43,22 @@ const RouterGuard = ({ children }: { children: any }) => {

setUserInfo(JSON.stringify(user));

// if (isAdmin(user)) {
// return;
// }
if (isAdmin(user)) {
return;
}

const path = url.split('?')[0];
if (!adminPaths.includes(path as string)) {
return;
}

// router.push({
// pathname: PublicPaths.HOME,
// });
router.push({
pathname: PublicPaths.HOME,
});
} catch (error) {
// router.push({
// pathname: PublicPaths.HOME,
// });
router.push({
pathname: PublicPaths.HOME,
});
}

return;
Expand Down
5 changes: 1 addition & 4 deletions packages/admin/src/utils/permission.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { RoleEnum, User } from '@mlem-admin/types/user';

export const isAdmin = (user: User) => {
return (
(user.roles && user.roles.includes(RoleEnum.ADMIN)) ||
(user.roles && user.roles.includes(RoleEnum.USER))
);
return user.roles && user.roles.includes(RoleEnum.ADMIN);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplification of the isAdmin function looks good. However, consider adding a nullish check for user.roles to ensure robustness, especially if there's any chance that user.roles might be undefined or null in some cases.

-  return user.roles && user.roles.includes(RoleEnum.ADMIN);
+  return user.roles?.includes(RoleEnum.ADMIN);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return user.roles && user.roles.includes(RoleEnum.ADMIN);
return user.roles?.includes(RoleEnum.ADMIN);

};
Loading