Skip to content

Commit 97db9b7

Browse files
author
Andrea Barbasso
committed
[DURACOM-309] fix issue after logging in
1 parent ab75cb8 commit 97db9b7

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

src/app/core/auth/auth.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ export class AuthService {
261261
);
262262
}
263263

264+
/**
265+
* Returns the authenticated user id from the store
266+
* @returns {User}
267+
*/
268+
public getAuthenticatedUserIdFromStore(): Observable<string> {
269+
return this.store.pipe(
270+
select(getAuthenticatedUserId),
271+
);
272+
}
273+
264274
/**
265275
* Checks if token is present into browser storage and is valid.
266276
*/

src/app/shared/cookies/browser-orejime.service.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ export class BrowserOrejimeService extends OrejimeService {
188188
* Return saved preferences stored in the orejime cookie
189189
*/
190190
getSavedPreferences(): Observable<any> {
191-
return this.getUser$().pipe(
192-
map((user: EPerson) => {
191+
return this.getUserId$().pipe(
192+
map((userId: string) => {
193193
let storageName;
194-
if (isEmpty(user)) {
194+
if (isEmpty(userId)) {
195195
storageName = ANONYMOUS_STORAGE_NAME_OREJIME;
196196
} else {
197-
storageName = this.getStorageName(user.uuid);
197+
storageName = this.getStorageName(userId);
198198
}
199199
return this.cookieService.get(storageName);
200200
}),
@@ -218,6 +218,24 @@ export class BrowserOrejimeService extends OrejimeService {
218218
}
219219
}
220220

221+
/**
222+
* Retrieves the currently logged in user id
223+
* Returns undefined when no one is logged in
224+
*/
225+
private getUserId$() {
226+
return this.authService.isAuthenticated()
227+
.pipe(
228+
take(1),
229+
switchMap((loggedIn: boolean) => {
230+
if (loggedIn) {
231+
return this.authService.getAuthenticatedUserIdFromStore();
232+
}
233+
return observableOf(undefined);
234+
}),
235+
take(1),
236+
);
237+
}
238+
221239
/**
222240
* Retrieves the currently logged in user
223241
* Returns undefined when no one is logged in

src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const ePersonMock: EPerson = Object.assign(new EPerson(), {
111111
uuid: '0a53a0f2-e168-4ed9-b4af-cba9a2d267ca',
112112
language: null,
113113
value:
114-
'{"authentication":true,"preferences":true,"acknowledgement":true,"google-analytics":true}',
114+
'{"authentication":true,"preferences":true,"acknowledgement":true,"google-analytics":true,"correlation-id":true}',
115115
place: 0,
116116
authority: null,
117117
confidence: -1,

0 commit comments

Comments
 (0)