mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
125969: Get rid of REQUEST and RESPONSE imports in AuthService
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { Inject, Injectable, Optional } from '@angular/core';
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';
|
||||
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { filter, map, startWith, switchMap, take } from 'rxjs/operators';
|
||||
@@ -79,9 +78,8 @@ export class AuthService {
|
||||
*/
|
||||
private tokenRefreshTimer;
|
||||
|
||||
constructor(@Inject(REQUEST) protected req: any,
|
||||
constructor(
|
||||
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
||||
@Optional() @Inject(RESPONSE) private response: any,
|
||||
protected authRequestService: AuthRequestService,
|
||||
protected epersonService: EPersonDataService,
|
||||
protected router: Router,
|
||||
@@ -89,8 +87,8 @@ export class AuthService {
|
||||
protected storage: CookieService,
|
||||
protected store: Store<AppState>,
|
||||
protected hardRedirectService: HardRedirectService,
|
||||
private notificationService: NotificationsService,
|
||||
private translateService: TranslateService
|
||||
protected notificationService: NotificationsService,
|
||||
protected translateService: TranslateService
|
||||
) {
|
||||
this.store.pipe(
|
||||
// when this service is constructed the store is not fully initialized yet
|
||||
@@ -473,10 +471,6 @@ export class AuthService {
|
||||
if (this._window.nativeWindow.location) {
|
||||
// Hard redirect to login page, so that all state is definitely lost
|
||||
this._window.nativeWindow.location.href = redirectUrl;
|
||||
} else if (this.response) {
|
||||
if (!this.response._headerSent) {
|
||||
this.response.redirect(302, redirectUrl);
|
||||
}
|
||||
} else {
|
||||
this.router.navigateByUrl(redirectUrl);
|
||||
}
|
||||
|
@@ -1,15 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable, Inject, Optional } from '@angular/core';
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
|
||||
import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
|
||||
import { AuthService } from './auth.service';
|
||||
import { AuthService, LOGIN_ROUTE } from './auth.service';
|
||||
import { AuthStatus } from './models/auth-status.model';
|
||||
import { AuthTokenInfo } from './models/auth-token-info.model';
|
||||
import { RemoteData } from '../data/remote-data';
|
||||
import { NativeWindowService, NativeWindowRef } from '../services/window.service';
|
||||
import { AuthRequestService } from './auth-request.service';
|
||||
import { EPersonDataService } from '../eperson/eperson-data.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { RouteService } from '../services/route.service';
|
||||
import { CookieService } from '../services/cookie.service';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppState } from '../../app.reducer';
|
||||
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
/**
|
||||
* The auth service.
|
||||
@@ -17,6 +27,34 @@ import { RemoteData } from '../data/remote-data';
|
||||
@Injectable()
|
||||
export class ServerAuthService extends AuthService {
|
||||
|
||||
constructor(
|
||||
@Inject(REQUEST) protected req: any,
|
||||
@Optional() @Inject(RESPONSE) private response: any,
|
||||
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
||||
protected authRequestService: AuthRequestService,
|
||||
protected epersonService: EPersonDataService,
|
||||
protected router: Router,
|
||||
protected routeService: RouteService,
|
||||
protected storage: CookieService,
|
||||
protected store: Store<AppState>,
|
||||
protected hardRedirectService: HardRedirectService,
|
||||
protected notificationService: NotificationsService,
|
||||
protected translateService: TranslateService
|
||||
) {
|
||||
super(
|
||||
_window,
|
||||
authRequestService,
|
||||
epersonService,
|
||||
router,
|
||||
routeService,
|
||||
storage,
|
||||
store,
|
||||
hardRedirectService,
|
||||
notificationService,
|
||||
translateService
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authenticated user
|
||||
* @returns {User}
|
||||
@@ -60,4 +98,18 @@ export class ServerAuthService extends AuthService {
|
||||
map((rd: RemoteData<AuthStatus>) => Object.assign(new AuthStatus(), rd.payload))
|
||||
);
|
||||
}
|
||||
|
||||
override redirectToLoginWhenTokenExpired() {
|
||||
const redirectUrl = LOGIN_ROUTE + '?expired=true';
|
||||
if (this._window.nativeWindow.location) {
|
||||
// Hard redirect to login page, so that all state is definitely lost
|
||||
this._window.nativeWindow.location.href = redirectUrl;
|
||||
} else if (this.response) {
|
||||
if (!this.response._headerSent) {
|
||||
this.response.redirect(302, redirectUrl);
|
||||
}
|
||||
} else {
|
||||
this.router.navigateByUrl(redirectUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user