From 852b9a7b219dda19e915f7c34670052b0999a213 Mon Sep 17 00:00:00 2001 From: Afra Hussaindeen Date: Tue, 24 Sep 2024 08:30:16 +0530 Subject: [PATCH 1/4] Fix issue for getting unauthorized for users without tenant association --- apps/console/src/hooks/use-routes.tsx | 6 ++++-- apps/console/src/protected-app.tsx | 14 +++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/console/src/hooks/use-routes.tsx b/apps/console/src/hooks/use-routes.tsx index 59e0b2ceeca..edb85ed6361 100644 --- a/apps/console/src/hooks/use-routes.tsx +++ b/apps/console/src/hooks/use-routes.tsx @@ -42,6 +42,7 @@ import { getAppViewRoutes } from "../configs/routes"; export type useRoutesInterface = { filterRoutes: ( onRoutesFilterComplete: () => void, + isUserTenantless: boolean, isFirstLevelOrg?: boolean ) => void; }; @@ -67,11 +68,12 @@ const useRoutes = (): useRoutesInterface => { * Filter the routes based on the user roles and permissions. * * @param onRoutesFilterComplete - Callback to be called after the routes are filtered. + * @param isUserTenantless - Indicates whether the user have any associated tenant. * @param isFirstLevelOrg - Is the current organization the first level organization. * * @returns A promise containing void. */ - const filterRoutes = async (onRoutesFilterComplete: () => void): Promise => { + const filterRoutes = async (onRoutesFilterComplete: () => void, isUserTenantless: boolean): Promise => { if ( isEmpty(allowedScopes) || !featureConfig.applications || @@ -154,7 +156,7 @@ const useRoutes = (): useRoutesInterface => { dispatch(setDeveloperVisibility(false)); } - if (sanitizedAppRoutes.length < 1) { + if (sanitizedAppRoutes.length < 1 && !isUserTenantless) { history.push({ pathname: AppConstants.getPaths().get("UNAUTHORIZED"), search: diff --git a/apps/console/src/protected-app.tsx b/apps/console/src/protected-app.tsx index 4a60f0d0c59..fb32144975e 100644 --- a/apps/console/src/protected-app.tsx +++ b/apps/console/src/protected-app.tsx @@ -117,7 +117,7 @@ export const ProtectedApp: FunctionComponent = (): ReactEleme const [ renderApp, setRenderApp ] = useState(false); const [ routesFiltered, setRoutesFiltered ] = useState(false); - const [ isRedirectingToTenantCreation, setRedirectingToTenantCreation ] = useState(false); + const [ isUserTenantless, setIsUserTenantless ] = useState(undefined); useEffect(() => { dispatch( @@ -231,11 +231,11 @@ export const ProtectedApp: FunctionComponent = (): ReactEleme idToken.sub)) ? AppConstants.getAppHomePath() : AuthenticationCallbackUrl; - + setIsUserTenantless(false); history.push(location); } else { - // If there is no assocation, the user should be redirected to creation flow. - setRedirectingToTenantCreation(true); + // If there is no association, the user should be redirected to creation flow. + setIsUserTenantless(true); history.push({ pathname: AppConstants.getPaths().get( "CREATE_TENANT" @@ -350,12 +350,12 @@ export const ProtectedApp: FunctionComponent = (): ReactEleme }, [ state.isAuthenticated ]); useEffect(() => { - if (!state.isAuthenticated || isRedirectingToTenantCreation) { + if (!state.isAuthenticated || isUserTenantless === undefined) { return; } - filterRoutes(() => setRoutesFiltered(true), isFirstLevelOrg); - }, [ filterRoutes, state.isAuthenticated, isFirstLevelOrg, isRedirectingToTenantCreation ]); + filterRoutes(() => setRoutesFiltered(true), isUserTenantless, isFirstLevelOrg); + }, [ filterRoutes, state.isAuthenticated, isFirstLevelOrg, isUserTenantless ]); return ( Date: Tue, 24 Sep 2024 08:41:21 +0530 Subject: [PATCH 2/4] Fix eslint issues --- apps/console/src/protected-app.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/console/src/protected-app.tsx b/apps/console/src/protected-app.tsx index fb32144975e..6ef5846841a 100644 --- a/apps/console/src/protected-app.tsx +++ b/apps/console/src/protected-app.tsx @@ -231,6 +231,7 @@ export const ProtectedApp: FunctionComponent = (): ReactEleme idToken.sub)) ? AppConstants.getAppHomePath() : AuthenticationCallbackUrl; + setIsUserTenantless(false); history.push(location); } else { From 38b68c96f7e5100d7e062421d75893b3a46674bf Mon Sep 17 00:00:00 2001 From: Afra Hussaindeen Date: Tue, 24 Sep 2024 08:48:45 +0530 Subject: [PATCH 3/4] =?UTF-8?q?Add=20changeset=20=F0=9F=A6=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/cold-parents-decide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cold-parents-decide.md diff --git a/.changeset/cold-parents-decide.md b/.changeset/cold-parents-decide.md new file mode 100644 index 00000000000..25011773b39 --- /dev/null +++ b/.changeset/cold-parents-decide.md @@ -0,0 +1,5 @@ +--- +"@wso2is/console": patch +--- + +Fix issue for getting unauthorized for users without tenant association From 0569a5a598804dd861d7f6c1bc57047a85a6def7 Mon Sep 17 00:00:00 2001 From: Afra Hussaindeen Date: Tue, 24 Sep 2024 16:16:06 +0530 Subject: [PATCH 4/4] Remove invalid condition --- apps/console/src/protected-app.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/console/src/protected-app.tsx b/apps/console/src/protected-app.tsx index 6ef5846841a..4603ec4ac5a 100644 --- a/apps/console/src/protected-app.tsx +++ b/apps/console/src/protected-app.tsx @@ -351,7 +351,7 @@ export const ProtectedApp: FunctionComponent = (): ReactEleme }, [ state.isAuthenticated ]); useEffect(() => { - if (!state.isAuthenticated || isUserTenantless === undefined) { + if (!state.isAuthenticated) { return; }