Skip to content

Instantly share code, notes, and snippets.

@cironunes
Last active August 9, 2017 20:51
Show Gist options
  • Save cironunes/c5751e7ddc52826ab7f4862960c4da43 to your computer and use it in GitHub Desktop.
Save cironunes/c5751e7ddc52826ab7f4862960c4da43 to your computer and use it in GitHub Desktop.
Angular 4.3.0+ Auth HttpInterceptor example
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