Instantly share code, notes, and snippets.

@wKoza /interceptor.ts Secret
Created Aug 10, 2017

Embed
What would you like to do?
import {Injectable} from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';
@Injectable()
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