Skip to content

Instantly share code, notes, and snippets.

Created Aug 10, 2017
What would you like to do?
import {Injectable} from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';
export class AuthInterceptor implements HttpInterceptor {
constructor(private auth: AuthService) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Clone the request to add the new header.
const authReq = req.clone({headers: req.headers.set('Authorization', 'my-token')});
// Pass on the cloned request instead of the original request.
return next.handle(authReq);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment