RED-6604: refactoring

This commit is contained in:
George 2023-04-21 15:44:36 +03:00
parent b024e3ef0b
commit cc90d9a561

View File

@ -43,9 +43,7 @@ export class TenantsService {
if (tenant) { if (tenant) {
this.#logger.info('[TENANTS] Tenant from route: ', tenant); this.#logger.info('[TENANTS] Tenant from route: ', tenant);
if (await this.selectTenant(tenant)) { if (await this.selectTenant(tenant)) {
const intendedPath = window.location.pathname.replace(this.#baseHref, ''); await this.#executeMainResolverAndRedirect(tenant);
await this.#router.navigate([tenant], { skipLocationChange: true });
await this.#router.navigateByUrl(intendedPath);
} }
return; return;
} }
@ -56,7 +54,7 @@ export class TenantsService {
this.#logger.info('[TENANTS] Only one tenant loaded, auto-select it and redirect to login page'); this.#logger.info('[TENANTS] Only one tenant loaded, auto-select it and redirect to login page');
const tenant = tenants[0].tenantId; const tenant = tenants[0].tenantId;
if (await this.selectTenant(tenant)) { 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); 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]);
}
} }