Skip to content

Commit f82426b

Browse files
committed
125969: Get rid of REQUEST and RESPONSE imports in AuthService
1 parent 8b90d99 commit f82426b

2 files changed

Lines changed: 68 additions & 22 deletions

File tree

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Inject, Injectable, Optional } from '@angular/core';
1+
import { Inject, Injectable } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { HttpHeaders } from '@angular/common/http';
4-
import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';
54

65
import { Observable, of as observableOf } from 'rxjs';
76
import { filter, map, startWith, switchMap, take } from 'rxjs/operators';
@@ -79,18 +78,17 @@ export class AuthService {
7978
*/
8079
private tokenRefreshTimer;
8180

82-
constructor(@Inject(REQUEST) protected req: any,
83-
@Inject(NativeWindowService) protected _window: NativeWindowRef,
84-
@Optional() @Inject(RESPONSE) private response: any,
85-
protected authRequestService: AuthRequestService,
86-
protected epersonService: EPersonDataService,
87-
protected router: Router,
88-
protected routeService: RouteService,
89-
protected storage: CookieService,
90-
protected store: Store<AppState>,
91-
protected hardRedirectService: HardRedirectService,
92-
private notificationService: NotificationsService,
93-
private translateService: TranslateService
81+
constructor(
82+
@Inject(NativeWindowService) protected _window: NativeWindowRef,
83+
protected authRequestService: AuthRequestService,
84+
protected epersonService: EPersonDataService,
85+
protected router: Router,
86+
protected routeService: RouteService,
87+
protected storage: CookieService,
88+
protected store: Store<AppState>,
89+
protected hardRedirectService: HardRedirectService,
90+
protected notificationService: NotificationsService,
91+
protected translateService: TranslateService
9492
) {
9593
this.store.pipe(
9694
// when this service is constructed the store is not fully initialized yet
@@ -473,10 +471,6 @@ export class AuthService {
473471
if (this._window.nativeWindow.location) {
474472
// Hard redirect to login page, so that all state is definitely lost
475473
this._window.nativeWindow.location.href = redirectUrl;
476-
} else if (this.response) {
477-
if (!this.response._headerSent) {
478-
this.response.redirect(302, redirectUrl);
479-
}
480474
} else {
481475
this.router.navigateByUrl(redirectUrl);
482476
}

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

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,60 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, Inject, Optional } from '@angular/core';
22
import { HttpHeaders } from '@angular/common/http';
3-
3+
import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';
44
import { Observable } from 'rxjs';
55
import { map } from 'rxjs/operators';
6-
76
import { hasValue, isNotEmpty } from '../../shared/empty.util';
87
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
9-
import { AuthService } from './auth.service';
8+
import { AuthService, LOGIN_ROUTE } from './auth.service';
109
import { AuthStatus } from './models/auth-status.model';
1110
import { AuthTokenInfo } from './models/auth-token-info.model';
1211
import { RemoteData } from '../data/remote-data';
12+
import { NativeWindowService, NativeWindowRef } from '../services/window.service';
13+
import { AuthRequestService } from './auth-request.service';
14+
import { EPersonDataService } from '../eperson/eperson-data.service';
15+
import { Router } from '@angular/router';
16+
import { RouteService } from '../services/route.service';
17+
import { CookieService } from '../services/cookie.service';
18+
import { Store } from '@ngrx/store';
19+
import { AppState } from '../../app.reducer';
20+
import { HardRedirectService } from '../services/hard-redirect.service';
21+
import { NotificationsService } from '../../shared/notifications/notifications.service';
22+
import { TranslateService } from '@ngx-translate/core';
1323

1424
/**
1525
* The auth service.
1626
*/
1727
@Injectable()
1828
export class ServerAuthService extends AuthService {
1929

30+
constructor(
31+
@Inject(REQUEST) protected req: any,
32+
@Optional() @Inject(RESPONSE) private response: any,
33+
@Inject(NativeWindowService) protected _window: NativeWindowRef,
34+
protected authRequestService: AuthRequestService,
35+
protected epersonService: EPersonDataService,
36+
protected router: Router,
37+
protected routeService: RouteService,
38+
protected storage: CookieService,
39+
protected store: Store<AppState>,
40+
protected hardRedirectService: HardRedirectService,
41+
protected notificationService: NotificationsService,
42+
protected translateService: TranslateService
43+
) {
44+
super(
45+
_window,
46+
authRequestService,
47+
epersonService,
48+
router,
49+
routeService,
50+
storage,
51+
store,
52+
hardRedirectService,
53+
notificationService,
54+
translateService
55+
);
56+
}
57+
2058
/**
2159
* Returns the authenticated user
2260
* @returns {User}
@@ -60,4 +98,18 @@ export class ServerAuthService extends AuthService {
6098
map((rd: RemoteData<AuthStatus>) => Object.assign(new AuthStatus(), rd.payload))
6199
);
62100
}
101+
102+
override redirectToLoginWhenTokenExpired() {
103+
const redirectUrl = LOGIN_ROUTE + '?expired=true';
104+
if (this._window.nativeWindow.location) {
105+
// Hard redirect to login page, so that all state is definitely lost
106+
this._window.nativeWindow.location.href = redirectUrl;
107+
} else if (this.response) {
108+
if (!this.response._headerSent) {
109+
this.response.redirect(302, redirectUrl);
110+
}
111+
} else {
112+
this.router.navigateByUrl(redirectUrl);
113+
}
114+
}
63115
}

0 commit comments

Comments
 (0)