Merge branch 'VM/RED-7874' into 'unprotected'

RED-7874 - Integrate "user has no roles" message in sign-in page

See merge request fforesight/shared-ui-libraries/common-ui!9
This commit is contained in:
Nicoleta Panaghiu 2024-02-20 14:56:43 +01:00
commit 0010eba410
5 changed files with 17 additions and 7 deletions

View File

@ -8,8 +8,8 @@
<iqser-spacer [height]="100"></iqser-spacer>
<ng-container *ngIf="isLoggedOut">
<div class="heading-xl" translate="tenant-resolve.header.youre-logged-out"></div>
<ng-container *ngIf="isLoggedOut || noRoleLogOut">
<div class="heading-xl" [translate]="isLoggedOut ? translations.IS_LOGGED_OUT : translations.NO_ROLE_LOG_OUT"></div>
<iqser-spacer [height]="75"></iqser-spacer>
</ng-container>

View File

@ -9,6 +9,7 @@ import { getKeycloakOptions } from '../keycloak-initializer';
import { IStoredTenantId, TenantsService } from '../services';
import { KeycloakStatusService } from '../services/keycloak-status.service';
import { UI_ROOT } from '../../utils';
import { selectTenantTranslations } from '../../translations/select-tenant-translations';
@Component({
templateUrl: './tenant-select.component.html',
@ -17,6 +18,7 @@ import { UI_ROOT } from '../../utils';
})
export class TenantSelectComponent {
@Input() isLoggedOut = false;
@Input() noRoleLogOut = false;
protected readonly logger = inject(NGXLogger);
protected readonly tenantsService = inject(TenantsService);
protected storedTenants: IStoredTenantId[] = [];
@ -29,6 +31,7 @@ export class TenantSelectComponent {
// eslint-disable-next-line @typescript-eslint/unbound-method
tenantId: ['', Validators.required],
});
protected readonly translations = selectTenantTranslations;
readonly #uiRoot = inject(UI_ROOT);
constructor() {

View File

@ -0,0 +1,6 @@
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
export const selectTenantTranslations: { [key in string]: string } = {
IS_LOGGED_OUT: _('tenant-resolve.header.youre-logged-out'),
NO_ROLE_LOG_OUT: _('tenant-resolve.header.no-role-log-out'),
} as const;

View File

@ -17,11 +17,11 @@ export function doesNotHaveAnyRole(): AsyncGuard {
export function hasAnyRole(): AsyncGuard {
return async () => {
const router = inject(Router);
const user = await inject(IqserUserService).loadCurrentUser();
const userService = inject(IqserUserService);
const user = await userService.loadCurrentUser();
if (!user?.hasAnyRole) {
await router.navigate(['auth-error']);
await userService.logout(true);
return false;
}
return true;

View File

@ -58,11 +58,12 @@ export abstract class IqserUserService<
await firstValueFrom(this.loadAll());
}
async logout() {
async logout(noRoleLogOut = false) {
try {
await this._keycloakService.loadUserProfile(true);
await this._cacheApiService.wipeCaches();
const redirectUri = window.location.origin + this.#uiRoot + '/?isLoggedOut=true';
const logoutParam = noRoleLogOut ? 'noRoleLogOut' : 'isLoggedOut';
const redirectUri = window.location.origin + this.#uiRoot + `/?${logoutParam}=true`;
await this._keycloakService.logout(redirectUri);
} catch (e) {
console.log('Logout failed: ', e);