70373: Store authenticated EPerson ID in store instead of object

This commit is contained in:
Kristof De Langhe
2020-04-15 11:14:41 +02:00
parent 638793ca5e
commit e43aa15a70
8 changed files with 72 additions and 38 deletions

View File

@@ -43,6 +43,7 @@ import {
RetrieveAuthMethodsSuccessAction,
RetrieveTokenAction
} from './auth.actions';
import { hasValue } from '../../shared/empty.util';
@Injectable()
export class AuthEffects {
@@ -97,8 +98,15 @@ export class AuthEffects {
public retrieveAuthenticatedEperson$: Observable<Action> = this.actions$.pipe(
ofType(AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON),
switchMap((action: RetrieveAuthenticatedEpersonAction) => {
return this.authService.retrieveAuthenticatedUserByHref(action.payload).pipe(
map((user: EPerson) => new RetrieveAuthenticatedEpersonSuccessAction(user)),
const impersonatedUserID = this.authService.getImpersonateID();
let user$: Observable<EPerson>;
if (hasValue(impersonatedUserID)) {
user$ = this.authService.retrieveAuthenticatedUserById(impersonatedUserID);
} else {
user$ = this.authService.retrieveAuthenticatedUserByHref(action.payload);
}
return user$.pipe(
map((user: EPerson) => new RetrieveAuthenticatedEpersonSuccessAction(user.id)),
catchError((error) => observableOf(new RetrieveAuthenticatedEpersonErrorAction(error))));
})
);