Last active
August 9, 2017 20:51
-
-
Save cironunes/c5751e7ddc52826ab7f4862960c4da43 to your computer and use it in GitHub Desktop.
Angular 4.3.0+ Auth HttpInterceptor example
This file contains 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
import { Injectable } from '@angular/core'; | |
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpEventType } from '@angular/common/http'; | |
import { Observable } from 'rxjs/Observable'; | |
export class AuthInterceptor implements HttpInterceptor { | |
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<HttpEventType.Response>> { | |
const authReq = req.clone({ | |
setHeaders: { Authorization: `Bearer authtest` } | |
}); | |
return next.handle(authReq); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment