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

Fix issue for getting unauthorized for users without tenant association #6914

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/cold-parents-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/console": patch
---

Fix issue for getting unauthorized for users without tenant association
6 changes: 4 additions & 2 deletions apps/console/src/hooks/use-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { getAppViewRoutes } from "../configs/routes";
export type useRoutesInterface = {
filterRoutes: (
onRoutesFilterComplete: () => void,
isUserTenantless: boolean,
isFirstLevelOrg?: boolean
) => void;
};
Expand All @@ -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<void> => {
const filterRoutes = async (onRoutesFilterComplete: () => void, isUserTenantless: boolean): Promise<void> => {
if (
isEmpty(allowedScopes) ||
!featureConfig.applications ||
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions apps/console/src/protected-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const ProtectedApp: FunctionComponent<AppPropsInterface> = (): ReactEleme

const [ renderApp, setRenderApp ] = useState<boolean>(false);
const [ routesFiltered, setRoutesFiltered ] = useState<boolean>(false);
const [ isRedirectingToTenantCreation, setRedirectingToTenantCreation ] = useState<boolean>(false);
const [ isUserTenantless, setIsUserTenantless ] = useState(undefined);

useEffect(() => {
dispatch(
Expand Down Expand Up @@ -232,10 +232,11 @@ export const ProtectedApp: FunctionComponent<AppPropsInterface> = (): ReactEleme
? AppConstants.getAppHomePath()
: AuthenticationCallbackUrl;

setIsUserTenantless(false);
AfraHussaindeen marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand Down Expand Up @@ -350,12 +351,12 @@ export const ProtectedApp: FunctionComponent<AppPropsInterface> = (): 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 (
<SecureApp
Expand Down
Loading