From 791df6f330e520fe99ccb80f42e00e1e040ac1c2 Mon Sep 17 00:00:00 2001 From: vivek kasture Date: Thu, 12 Dec 2024 00:03:57 +0530 Subject: [PATCH] Issue #PS-0000 fix: Fixed showing edit-password --- src/components/RouteGuard.tsx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/RouteGuard.tsx b/src/components/RouteGuard.tsx index 0b6c68fa..2c742f05 100644 --- a/src/components/RouteGuard.tsx +++ b/src/components/RouteGuard.tsx @@ -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) { @@ -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", @@ -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 @@ -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) { @@ -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"); } } @@ -110,4 +110,4 @@ const RouteGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => { return <>{children}; }; -export default RouteGuard; +export default RouteGuard; \ No newline at end of file