Created
July 31, 2018 19:28
-
-
Save whisher/56d163a40b5858d6eeece880a4ca4659 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | |
| return this.store.select(fromStore.getToken) | |
| .pipe( | |
| take(1), | |
| switchMap((token: AuthenticationToken) => { | |
| console.log('token',token); | |
| if (token) { | |
| const clonedRequest = request.clone({ | |
| setHeaders: { | |
| Authorization: `Bearer ${token.token}` | |
| } | |
| }); | |
| return next.handle(clonedRequest); | |
| } | |
| return next.handle(request); | |
| }) | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment