RED-3800 move if not logged in guard
This commit is contained in:
parent
f4f2dcb2d3
commit
cfe5a32ebc
@ -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';
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
export function getRouteTenant() {
|
||||
const pathParams = location.pathname.split('/').filter(Boolean);
|
||||
const uiPathIndex = pathParams.indexOf('ui');
|
||||
return pathParams[uiPathIndex + 1];
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user