|
1 | | -import { Injectable, Optional, Inject } from '@angular/core'; |
| 1 | +import { Injectable, Optional, Inject, PLATFORM_ID } from '@angular/core'; |
2 | 2 | import { ActivatedRoute, Router, CanActivate } from '@angular/router'; |
3 | 3 | import { HttpClient } from '@angular/common/http'; |
| 4 | +import { isPlatformServer } from '@angular/common'; |
4 | 5 |
|
5 | 6 | import { Observable, fromEvent, interval } from 'rxjs'; |
6 | | -import { pluck, filter, tap, share, finalize } from 'rxjs/operators'; |
| 7 | +import { pluck, filter, share, finalize } from 'rxjs/operators'; |
7 | 8 |
|
8 | 9 | import { ANGULAR_TOKEN_OPTIONS } from './angular-token.token'; |
9 | 10 |
|
@@ -53,9 +54,20 @@ export class AngularTokenService implements CanActivate { |
53 | 54 | constructor( |
54 | 55 | private http: HttpClient, |
55 | 56 | @Inject(ANGULAR_TOKEN_OPTIONS) config: any, |
| 57 | + @Inject(PLATFORM_ID) private platformId: Object, |
56 | 58 | @Optional() private activatedRoute: ActivatedRoute, |
57 | 59 | @Optional() private router: Router |
58 | 60 | ) { |
| 61 | + if (isPlatformServer(platformId)) { |
| 62 | + window = { |
| 63 | + open: () => null, |
| 64 | + location: { |
| 65 | + href: '/', |
| 66 | + origin: '/' |
| 67 | + } |
| 68 | + } as Window; |
| 69 | + } |
| 70 | + |
59 | 71 | const defaultOptions: AngularTokenOptions = { |
60 | 72 | apiPath: null, |
61 | 73 | apiBase: null, |
|
0 commit comments