From cc90d9a561f4cc1cea277b924775b1b0c62dafa5 Mon Sep 17 00:00:00 2001 From: George Date: Fri, 21 Apr 2023 15:44:36 +0300 Subject: [PATCH] RED-6604: refactoring --- src/lib/tenants/services/tenants.service.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/tenants/services/tenants.service.ts b/src/lib/tenants/services/tenants.service.ts index 587243e..0fa0774 100644 --- a/src/lib/tenants/services/tenants.service.ts +++ b/src/lib/tenants/services/tenants.service.ts @@ -43,9 +43,7 @@ export class TenantsService { if (tenant) { this.#logger.info('[TENANTS] Tenant from route: ', tenant); if (await this.selectTenant(tenant)) { - const intendedPath = window.location.pathname.replace(this.#baseHref, ''); - await this.#router.navigate([tenant], { skipLocationChange: true }); - await this.#router.navigateByUrl(intendedPath); + await this.#executeMainResolverAndRedirect(tenant); } return; } @@ -56,7 +54,7 @@ export class TenantsService { this.#logger.info('[TENANTS] Only one tenant loaded, auto-select it and redirect to login page'); const tenant = tenants[0].tenantId; if (await this.selectTenant(tenant)) { - await this.#router.navigate([tenant]); + await this.#executeMainResolverAndRedirect(tenant); } } } @@ -102,4 +100,11 @@ export class TenantsService { this.#storageReference.removeItem(tenant + ':' + key); }; } + + async #executeMainResolverAndRedirect(tenant: string) { + const intendedPath = window.location.pathname.replace(this.#baseHref, ''); + // TODO: Load roles in child routes canLoad functions so we can redirect straight to wanted URL + await this.#router.navigate([tenant], { skipLocationChange: true }); + await this.#router.navigate([intendedPath]); + } }