RED-3800 - fix tenant switch.
This commit is contained in:
parent
68dbdfb8e7
commit
c4bdba4683
@ -1,16 +1,16 @@
|
|||||||
import { inject, Injectable } from '@angular/core';
|
import { inject, Injectable } from '@angular/core';
|
||||||
import { KeycloakService } from 'keycloak-angular';
|
import { KeycloakService } from 'keycloak-angular';
|
||||||
import { getConfig } from '../../services';
|
import { getConfig } from '../../services';
|
||||||
import { TenantsService } from '../index';
|
import { getKeycloakOptions, TenantsService } from '../index';
|
||||||
import { NGXLogger } from 'ngx-logger';
|
import { NGXLogger } from 'ngx-logger';
|
||||||
import { APP_BASE_HREF } from '@angular/common';
|
import { UI_ROOT } from '../../utils';
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class KeycloakStatusService {
|
export class KeycloakStatusService {
|
||||||
readonly #keycloakService = inject(KeycloakService);
|
readonly #keycloakService = inject(KeycloakService);
|
||||||
readonly #config = getConfig();
|
readonly #config = getConfig();
|
||||||
readonly #tenantsService = inject(TenantsService);
|
readonly #tenantsService = inject(TenantsService);
|
||||||
readonly #baseHref = inject(APP_BASE_HREF);
|
readonly #uiRoot = inject(UI_ROOT);
|
||||||
readonly #logger = inject(NGXLogger);
|
readonly #logger = inject(NGXLogger);
|
||||||
|
|
||||||
createLoginUrlAndExecute(username?: string | null) {
|
createLoginUrlAndExecute(username?: string | null) {
|
||||||
@ -34,12 +34,15 @@ export class KeycloakStatusService {
|
|||||||
let redirectUri: string;
|
let redirectUri: string;
|
||||||
|
|
||||||
if (tenantId) {
|
if (tenantId) {
|
||||||
redirectUri = this.#keycloakService.getKeycloakInstance().createLoginUrl({
|
await this.#tenantsService.selectTenant(tenantId);
|
||||||
|
const newKCInstance = new KeycloakService();
|
||||||
|
await newKCInstance.init(getKeycloakOptions(this.#uiRoot, this.#config, tenantId));
|
||||||
|
redirectUri = newKCInstance.getKeycloakInstance().createLoginUrl({
|
||||||
redirectUri: this.createLoginUrl(tenantId),
|
redirectUri: this.createLoginUrl(tenantId),
|
||||||
idpHint: this.#config.OAUTH_IDP_HINT,
|
idpHint: this.#config.OAUTH_IDP_HINT,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
redirectUri = window.location.origin + this.#baseHref;
|
redirectUri = window.location.origin + this.#uiRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.#keycloakService.logout(redirectUri);
|
await this.#keycloakService.logout(redirectUri);
|
||||||
@ -47,7 +50,7 @@ export class KeycloakStatusService {
|
|||||||
|
|
||||||
createLoginUrl(tenant?: string) {
|
createLoginUrl(tenant?: string) {
|
||||||
if (tenant && window.location.href.indexOf('/' + tenant + '/') > 0) {
|
if (tenant && window.location.href.indexOf('/' + tenant + '/') > 0) {
|
||||||
return window.location.href + '/main';
|
return window.location.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
const origin = window.location.origin;
|
const origin = window.location.origin;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user