Added action to retrieve authenticated eperson object

This commit is contained in:
Giuseppe Digilio
2020-03-02 13:09:17 +01:00
parent df8ef2b5c3
commit 18e17f0dad
11 changed files with 281 additions and 83 deletions

View File

@@ -2,11 +2,9 @@ import { HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { filter, map, switchMap, take } from 'rxjs/operators';
import { filter, map, take } from 'rxjs/operators';
import { isNotEmpty } from '../../shared/empty.util';
import { followLink } from '../../shared/utils/follow-link-config.model';
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
import { EPerson } from '../eperson/models/eperson.model';
import { CheckAuthenticationTokenAction } from './auth.actions';
import { AuthService } from './auth.service';
import { AuthStatus } from './models/auth-status.model';
@@ -22,7 +20,7 @@ export class ServerAuthService extends AuthService {
* Returns the authenticated user
* @returns {User}
*/
public authenticatedUser(token: AuthTokenInfo): Observable<EPerson> {
public authenticatedUser(token: AuthTokenInfo): Observable<string> {
// Determine if the user has an existing auth session on the server
const options: HttpOptions = Object.create({});
let headers = new HttpHeaders();
@@ -35,10 +33,9 @@ export class ServerAuthService extends AuthService {
options.headers = headers;
return this.authRequestService.getRequest('status', options).pipe(
map((status) => this.linkService.resolveLinks(status, followLink<AuthStatus>('eperson'))),
switchMap((status: AuthStatus) => {
map((status: AuthStatus) => {
if (status.authenticated) {
return status.eperson.pipe(map((eperson) => eperson.payload));
return status._links.eperson.href;
} else {
throw(new Error('Not authenticated'));
}