From 79d03d0433e10a5e54c31c3c206070a0515938d1 Mon Sep 17 00:00:00 2001 From: Andrea Barbasso <´andrea.barbasso@4science.com´> Date: Thu, 6 Feb 2025 15:22:02 +0100 Subject: [PATCH] [DURACOM-309] fix issue after logging in --- src/app/core/auth/auth.service.ts | 10 +++++++ .../shared/cookies/browser-orejime.service.ts | 26 ++++++++++++++++--- .../workspaceitem-actions.component.spec.ts | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index 47f71f8b7f..b81de56a69 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -256,6 +256,16 @@ export class AuthService { ); } + /** + * Returns the authenticated user id from the store + * @returns {User} + */ + public getAuthenticatedUserIdFromStore(): Observable { + return this.store.pipe( + select(getAuthenticatedUserId), + ); + } + /** * Checks if token is present into browser storage and is valid. */ diff --git a/src/app/shared/cookies/browser-orejime.service.ts b/src/app/shared/cookies/browser-orejime.service.ts index 1296f4c3c1..db29a9e7a2 100644 --- a/src/app/shared/cookies/browser-orejime.service.ts +++ b/src/app/shared/cookies/browser-orejime.service.ts @@ -229,13 +229,13 @@ export class BrowserOrejimeService extends OrejimeService { * Return saved preferences stored in the orejime cookie */ getSavedPreferences(): Observable { - return this.getUser$().pipe( - map((user: EPerson) => { + return this.getUserId$().pipe( + map((userId: string) => { let storageName; - if (isEmpty(user)) { + if (isEmpty(userId)) { storageName = ANONYMOUS_STORAGE_NAME_OREJIME; } else { - storageName = this.getStorageName(user.uuid); + storageName = this.getStorageName(userId); } return this.cookieService.get(storageName); }), @@ -258,6 +258,24 @@ export class BrowserOrejimeService extends OrejimeService { } } + /** + * Retrieves the currently logged in user id + * Returns undefined when no one is logged in + */ + private getUserId$() { + return this.authService.isAuthenticated() + .pipe( + take(1), + switchMap((loggedIn: boolean) => { + if (loggedIn) { + return this.authService.getAuthenticatedUserIdFromStore(); + } + return observableOf(undefined); + }), + take(1), + ); + } + /** * Retrieves the currently logged in user * Returns undefined when no one is logged in diff --git a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts index 1834aa31f1..12d00b27a7 100644 --- a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts +++ b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts @@ -111,7 +111,7 @@ const ePersonMock: EPerson = Object.assign(new EPerson(), { uuid: '0a53a0f2-e168-4ed9-b4af-cba9a2d267ca', language: null, value: - '{"authentication":true,"preferences":true,"acknowledgement":true,"google-analytics":true}', + '{"authentication":true,"preferences":true,"acknowledgement":true,"google-analytics":true,"correlation-id":true}', place: 0, authority: null, confidence: -1,