mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 02:54:13 +00:00
small fixes for authentication
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {first, map} from 'rxjs/operators';
|
||||
import { first, map, switchMap } from 'rxjs/operators';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
@@ -9,7 +9,8 @@ import { isNotEmpty } from '../../shared/empty.util';
|
||||
import { AuthService } from './auth.service';
|
||||
import { AuthTokenInfo } from './models/auth-token-info.model';
|
||||
import { CheckAuthenticationTokenAction } from './auth.actions';
|
||||
import { Eperson } from '../eperson/models/eperson.model';
|
||||
import { EPerson } from '../eperson/models/eperson.model';
|
||||
import { NormalizedEPerson } from '../eperson/models/normalized-eperson.model';
|
||||
|
||||
/**
|
||||
* The auth service.
|
||||
@@ -21,7 +22,7 @@ export class ServerAuthService extends AuthService {
|
||||
* Returns the authenticated user
|
||||
* @returns {User}
|
||||
*/
|
||||
public authenticatedUser(token: AuthTokenInfo): Observable<Eperson> {
|
||||
public authenticatedUser(token: AuthTokenInfo): Observable<EPerson> {
|
||||
// Determine if the user has an existing auth session on the server
|
||||
const options: HttpOptions = Object.create({});
|
||||
let headers = new HttpHeaders();
|
||||
@@ -34,13 +35,18 @@ export class ServerAuthService extends AuthService {
|
||||
|
||||
options.headers = headers;
|
||||
return this.authRequestService.getRequest('status', options).pipe(
|
||||
map((status: AuthStatus) => {
|
||||
switchMap((status: AuthStatus) => {
|
||||
|
||||
if (status.authenticated) {
|
||||
return status.eperson[0];
|
||||
|
||||
// TODO this should be cleaned up, AuthStatus could be parsed by the RemoteDataService as a whole...
|
||||
const person$ = this.rdbService.buildSingle<NormalizedEPerson, EPerson>(status.eperson.toString());
|
||||
// person$.subscribe(() => console.log('test'));
|
||||
return person$.pipe(map((eperson) => eperson.payload));
|
||||
} else {
|
||||
throw(new Error('Not authenticated'));
|
||||
Observable.throw(new Error('Not authenticated'));
|
||||
}
|
||||
}));
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user