diff --git a/apps/red-ui/src/app/app-routing.module.ts b/apps/red-ui/src/app/app-routing.module.ts index 68b2aa4ed..48b8cd5be 100644 --- a/apps/red-ui/src/app/app-routing.module.ts +++ b/apps/red-ui/src/app/app-routing.module.ts @@ -1,5 +1,6 @@ import { NgModule } from '@angular/core'; import { RouteReuseStrategy, RouterModule } from '@angular/router'; +import { ifNotLoggedIn } from '@common-ui/tenants/guards/if-not-logged-in.guard'; import { AuthErrorComponent } from '@components/auth-error/auth-error.component'; import { BaseScreenComponent } from '@components/base-screen/base-screen.component'; import { DownloadsListScreenComponent } from '@components/downloads-list-screen/downloads-list-screen.component'; @@ -11,7 +12,6 @@ import { loadActiveDossiersGuard, loadAllDossiersGuard, loadArchivedDossiersGuar import { editAttributeGuard } from '@guards/edit-attribute.guard'; import { FeaturesGuard } from '@guards/features-guard.service'; import { ifLoggedIn } from '@guards/if-logged-in.guard'; -import { ifNotLoggedIn } from '@guards/if-not-logged-in.guard'; import { TrashGuard } from '@guards/trash.guard'; import { CompositeRouteGuard, DEFAULT_REDIRECT_KEY, IqserPermissionsGuard, IqserRoutes, orderedAsyncGuards } from '@iqser/common-ui'; import { TenantSelectComponent } from '@iqser/common-ui/lib/tenants'; diff --git a/apps/red-ui/src/app/app.module.ts b/apps/red-ui/src/app/app.module.ts index 43417d861..b08d1384a 100644 --- a/apps/red-ui/src/app/app.module.ts +++ b/apps/red-ui/src/app/app.module.ts @@ -6,6 +6,7 @@ import { MAT_TOOLTIP_DEFAULT_OPTIONS } from '@angular/material/tooltip'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { ServiceWorkerModule } from '@angular/service-worker'; +import { GET_TENANT_FROM_PATH_FN, UI_ROOT } from '@common-ui/utils'; import { AuthErrorComponent } from '@components/auth-error/auth-error.component'; import { BaseScreenComponent } from '@components/base-screen/base-screen.component'; import { BreadcrumbsComponent } from '@components/breadcrumbs/breadcrumbs.component'; @@ -68,7 +69,6 @@ import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { PdfViewerModule } from './modules/pdf-viewer/pdf-viewer.module'; import { ACTIVE_DOSSIERS_SERVICE, ARCHIVED_DOSSIERS_SERVICE } from './tokens'; -import { GET_TENANT_FROM_PATH_FN, UI_ROOT } from '@common-ui/utils'; export const appModuleFactory = (config: AppConfig) => { @NgModule({ @@ -139,7 +139,7 @@ export const appModuleFactory = (config: AppConfig) => { enabled: false, }, TENANTS: { - enabled: false, + enabled: true, }, ROUTES: { enabled: true, diff --git a/apps/red-ui/src/app/guards/guards-utils.ts b/apps/red-ui/src/app/guards/guards-utils.ts deleted file mode 100644 index 250ecbab8..000000000 --- a/apps/red-ui/src/app/guards/guards-utils.ts +++ /dev/null @@ -1,5 +0,0 @@ -export function getRouteTenant() { - const pathParams = location.pathname.split('/').filter(Boolean); - const uiPathIndex = pathParams.indexOf('ui'); - return pathParams[uiPathIndex + 1]; -} diff --git a/apps/red-ui/src/app/guards/if-logged-in.guard.ts b/apps/red-ui/src/app/guards/if-logged-in.guard.ts index b081d408e..caf15c448 100644 --- a/apps/red-ui/src/app/guards/if-logged-in.guard.ts +++ b/apps/red-ui/src/app/guards/if-logged-in.guard.ts @@ -1,6 +1,6 @@ import { inject } from '@angular/core'; import { ActivatedRouteSnapshot, Router } from '@angular/router'; -import { getRouteTenant } from '@guards/guards-utils'; +import { GET_TENANT_FROM_PATH_FN } from '@common-ui/utils'; import { AsyncGuard } from '@iqser/common-ui'; import { keycloakInitializer, KeycloakStatusService, TenantsService } from '@iqser/common-ui/lib/tenants'; import { LicenseService } from '@services/license.service'; @@ -8,7 +8,6 @@ import { UserService } from '@users/user.service'; import { jwtDecode } from 'jwt-decode'; import { KeycloakService } from 'keycloak-angular'; import { NGXLogger } from 'ngx-logger'; -import { GET_TENANT_FROM_PATH_FN } from '@common-ui/utils'; export interface JwtToken { auth_time: number; diff --git a/apps/red-ui/src/app/guards/if-not-logged-in.guard.ts b/apps/red-ui/src/app/guards/if-not-logged-in.guard.ts deleted file mode 100644 index 25549b62c..000000000 --- a/apps/red-ui/src/app/guards/if-not-logged-in.guard.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { inject } from '@angular/core'; -import { CanActivateFn, Router } from '@angular/router'; -import { getRouteTenant } from '@guards/guards-utils'; -import { KeycloakService } from 'keycloak-angular'; -import { NGXLogger } from 'ngx-logger'; - -export function ifNotLoggedIn(): CanActivateFn { - return async () => { - const logger = inject(NGXLogger); - const router = inject(Router); - const keycloakService = inject(KeycloakService); - if (!keycloakService.getKeycloakInstance()) { - const tenant = getRouteTenant(); - if (tenant) { - logger.warn('[ROUTES] Tenant ' + tenant + ' found in route, redirecting to /main'); - await router.navigate(['main']); - return false; - } - } - - if (!keycloakService.isLoggedIn()) { - logger.info('[ROUTES] Not logged in, continuing to selected route'); - return true; - } - - const tenant = keycloakService.getKeycloakInstance().realm; - if (!tenant) { - logger.error('[ROUTES] Tenant not found in route or keycloak realm'); - return false; - } - - logger.warn('[ROUTES] Is logged in for ' + tenant + ', redirecting to /' + tenant); - await router.navigate(['/main']); - return false; - }; -}