Skip to content

Commit

Permalink
Issue #PS-0000 fix: Fixed showing edit-password
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvick committed Dec 11, 2024
1 parent 0861f8f commit 791df6f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/components/RouteGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const RouteGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => {
keysToKeep.forEach((key: string) => {
valuesToKeep[key] = localStorage.getItem(key);
});

// Clear all local storage
localStorage.clear();

// Re-add the keys to keep with their values
keysToKeep.forEach((key: string) => {
if (valuesToKeep[key] !== null) {
Expand All @@ -44,7 +44,7 @@ const RouteGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => {

const user = JSON.parse(adminInfo);

const allowedPaths = ["/workspace/content/create","/course-planner", "/subjectDetails","/stateDetails"];
const allowedPaths = ["/workspace/content/create", "/course-planner", "/subjectDetails", "/stateDetails"];
const isWorkspaceContent = router.pathname.startsWith("/workspace/content");
const coursePlannerPaths = [
"/course-planner",
Expand All @@ -62,12 +62,12 @@ const RouteGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => {
"/edit-password",
"/course-hierarchy"
];

const isCoursePlannerContent = coursePlannerPaths.some((path) =>
router.pathname.startsWith(path)
);

if ((user.role === Role.SCTA ||user.role === Role.CCTA)&& !(allowedPaths.includes(router.pathname) || isWorkspaceContent || isCoursePlannerContent)) {
if ((user.role === Role.SCTA || user.role === Role.CCTA) && !(allowedPaths.includes(router.pathname) || isWorkspaceContent || isCoursePlannerContent)) {
if (router.pathname !== "/login" && router.pathname !== "/logout") {
if (typeof window !== 'undefined' && window.localStorage) {
// Specify the keys you want to keep
Expand All @@ -83,10 +83,10 @@ const RouteGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => {
keysToKeep.forEach((key: string) => {
valuesToKeep[key] = localStorage.getItem(key);
});

// Clear all local storage
// localStorage.clear();

// // Re-add the keys to keep with their values
// keysToKeep.forEach((key: string) => {
// if (valuesToKeep[key] !== null) {
Expand All @@ -99,9 +99,9 @@ const RouteGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => {
}
}

if ((user.role === Role.ADMIN || user.role === Role.CENTRAL_ADMIN )&& (allowedPaths.includes(router.pathname) || isWorkspaceContent || isCoursePlannerContent)) {
if (router.pathname !== "/login" && router.pathname !== "/logout") {
if ((user.role === Role.ADMIN || user.role === Role.CENTRAL_ADMIN) && (allowedPaths.includes(router.pathname) || isWorkspaceContent || isCoursePlannerContent)) {
if (router.pathname !== "/login" && router.pathname !== "/logout" && router.pathname !== "/edit-password") {

router.push("/unauthorized");
}
}
Expand All @@ -110,4 +110,4 @@ const RouteGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => {
return <>{children}</>;
};

export default RouteGuard;
export default RouteGuard;

0 comments on commit 791df6f

Please sign in to comment.