RED-6713: remove stored tenant on logout
This commit is contained in:
parent
5449cacc2b
commit
a06124ab4e
@ -155,6 +155,30 @@ export class TenantsService {
|
|||||||
return trueStored;
|
return trueStored;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeStored(email: string) {
|
||||||
|
if (!email) {
|
||||||
|
this.#logger.warn('[TENANTS] Email is null, skip storing');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const storedTenants = this.getStoredTenants();
|
||||||
|
const activeTenant = this.activeTenant();
|
||||||
|
const existing = storedTenants.find(s => s.email === email && s.tenant.tenantId === activeTenant?.tenantId);
|
||||||
|
if (!existing) {
|
||||||
|
this.#logger.info('[TENANTS] No stored tenant for ', email);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const serializableTenants = storedTenants
|
||||||
|
.filter(s => s !== existing)
|
||||||
|
.map(s => ({
|
||||||
|
tenantId: s.tenant.tenantId,
|
||||||
|
email: s.email,
|
||||||
|
}));
|
||||||
|
this.#storageReference.setItem(STORED_TENANTS_KEY, JSON.stringify(serializableTenants));
|
||||||
|
this.#logger.info('[TENANTS] Stored tenants at logout: ', storedTenants);
|
||||||
|
}
|
||||||
|
|
||||||
#setActiveTenantId(tenantId: string) {
|
#setActiveTenantId(tenantId: string) {
|
||||||
this.#logger.info('[TENANTS] Set current tenant id: ', tenantId);
|
this.#logger.info('[TENANTS] Set current tenant id: ', tenantId);
|
||||||
this.#activeTenantId.set(tenantId);
|
this.#activeTenantId.set(tenantId);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { inject, Injectable } from '@angular/core';
|
|||||||
import { KeycloakService } from 'keycloak-angular';
|
import { KeycloakService } from 'keycloak-angular';
|
||||||
import { BehaviorSubject, firstValueFrom, Observable, throwError } from 'rxjs';
|
import { BehaviorSubject, firstValueFrom, Observable, throwError } from 'rxjs';
|
||||||
import { catchError, tap } from 'rxjs/operators';
|
import { catchError, tap } from 'rxjs/operators';
|
||||||
import { List, mapEach } from '../../utils';
|
import { BASE_HREF, List, mapEach } from '../../utils';
|
||||||
import { QueryParam, Toaster } from '../../services';
|
import { QueryParam, Toaster } from '../../services';
|
||||||
import { CacheApiService } from '../../caching';
|
import { CacheApiService } from '../../caching';
|
||||||
import { EntitiesService } from '../../listing';
|
import { EntitiesService } from '../../listing';
|
||||||
@ -16,7 +16,7 @@ import { IqserUser } from '../iqser-user.model';
|
|||||||
import { IqserPermissionsService, IqserRolesService } from '../../permissions';
|
import { IqserPermissionsService, IqserRolesService } from '../../permissions';
|
||||||
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
||||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||||
import { KeycloakStatusService } from '../../tenants';
|
import { KeycloakStatusService, TenantsService } from '../../tenants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export abstract class IqserUserService<
|
export abstract class IqserUserService<
|
||||||
@ -35,6 +35,8 @@ export abstract class IqserUserService<
|
|||||||
protected readonly _keycloakStatusService = inject(KeycloakStatusService);
|
protected readonly _keycloakStatusService = inject(KeycloakStatusService);
|
||||||
protected readonly _permissionsService = inject(IqserPermissionsService, { optional: true });
|
protected readonly _permissionsService = inject(IqserPermissionsService, { optional: true });
|
||||||
protected readonly _rolesService = inject(IqserRolesService, { optional: true });
|
protected readonly _rolesService = inject(IqserRolesService, { optional: true });
|
||||||
|
protected readonly _tenantsService = inject(TenantsService);
|
||||||
|
protected readonly _baseHref = inject(BASE_HREF);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -58,9 +60,10 @@ export abstract class IqserUserService<
|
|||||||
|
|
||||||
async logout() {
|
async logout() {
|
||||||
try {
|
try {
|
||||||
|
this._tenantsService.removeStored(this.currentUser?.email ?? '');
|
||||||
await this._keycloakService.loadUserProfile(true);
|
await this._keycloakService.loadUserProfile(true);
|
||||||
await this._cacheApiService.wipeCaches();
|
await this._cacheApiService.wipeCaches();
|
||||||
await this._keycloakService.logout(this._keycloakStatusService.createLoginUrl());
|
await this._keycloakService.logout(window.location.origin + this._baseHref);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Logout failed: ', e);
|
console.log('Logout failed: ', e);
|
||||||
await this.redirectToLogin();
|
await this.redirectToLogin();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user