mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Removed use of platform service and created different service for SSR and CSR
This commit is contained in:
@@ -15,11 +15,15 @@ import { CookieService } from '../../shared/services/cookie.service';
|
||||
import { getAuthenticationToken, getRedirectUrl, isAuthenticated, isTokenRefreshing } from './selectors';
|
||||
import { AppState, routerStateSelector } from '../../app.reducer';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { ResetAuthenticationMessagesAction, SetRedirectUrlAction } from './auth.actions';
|
||||
import {
|
||||
CheckAuthenticationTokenAction,
|
||||
ResetAuthenticationMessagesAction,
|
||||
SetRedirectUrlAction
|
||||
} from './auth.actions';
|
||||
import { RouterReducerState } from '@ngrx/router-store';
|
||||
import { CookieAttributes } from 'js-cookie';
|
||||
import { NativeWindowRef, NativeWindowService } from '../../shared/services/window.service';
|
||||
import { PlatformService } from '../../shared/services/platform.service';
|
||||
import { REQUEST } from '@nguniversal/express-engine/tokens';
|
||||
|
||||
export const LOGIN_ROUTE = '/login';
|
||||
|
||||
@@ -35,14 +39,14 @@ export class AuthService {
|
||||
* True if authenticated
|
||||
* @type boolean
|
||||
*/
|
||||
private _authenticated: boolean;
|
||||
protected _authenticated: boolean;
|
||||
|
||||
constructor(@Inject(NativeWindowService) private _window: NativeWindowRef,
|
||||
private authRequestService: AuthRequestService,
|
||||
private platform: PlatformService,
|
||||
private router: Router,
|
||||
private storage: CookieService,
|
||||
private store: Store<AppState>) {
|
||||
constructor(@Inject(REQUEST) protected req: any,
|
||||
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
||||
protected authRequestService: AuthRequestService,
|
||||
protected router: Router,
|
||||
protected storage: CookieService,
|
||||
protected store: Store<AppState>) {
|
||||
this.store.select(isAuthenticated)
|
||||
.startWith(false)
|
||||
.subscribe((authenticated: boolean) => this._authenticated = authenticated);
|
||||
@@ -130,10 +134,17 @@ export class AuthService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if token is present into browser storage and is valid. (NB Check is done only on SSR)
|
||||
*/
|
||||
public checksAuthenticationToken() {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if token is present into storage and is not expired
|
||||
*/
|
||||
public checkAuthenticationToken(): Observable<AuthTokenInfo> {
|
||||
public hasValidAuthenticationToken(): Observable<AuthTokenInfo> {
|
||||
return this.store.select(getAuthenticationToken)
|
||||
.take(1)
|
||||
.map((authTokenInfo: AuthTokenInfo) => {
|
||||
@@ -317,10 +328,9 @@ export class AuthService {
|
||||
this.getRedirectUrl()
|
||||
.first()
|
||||
.subscribe((redirectUrl) => {
|
||||
console.log('Browser');
|
||||
if (isNotEmpty(redirectUrl)) {
|
||||
if (this.platform.isBrowser) {
|
||||
this.clearRedirectUrl();
|
||||
}
|
||||
this.clearRedirectUrl();
|
||||
|
||||
// override the route reuse strategy
|
||||
this.router.routeReuseStrategy.shouldReuseRoute = () => {
|
||||
|
Reference in New Issue
Block a user