-
-
Save wKoza/4b95eba310ee6d6a284febe0216fbdb0 to your computer and use it in GitHub Desktop.
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 {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