Skip to content

Instantly share code, notes, and snippets.

@splincode
Last active May 17, 2020 15:59
Show Gist options
  • Save splincode/c01e0e3cae8019587d692ce2672e7739 to your computer and use it in GitHub Desktop.
Save splincode/c01e0e3cae8019587d692ce2672e7739 to your computer and use it in GitHub Desktop.
@Injectable()
export class TokenInterceptor {
constructor(private authInfo: AuthState) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (this.authInfo.snapshot.token) {
req = req.clone({
setHeaders: {
Authorization: `Bearer ${this.authInfo.snapshot.token}`,
},
});
}
return next.handle(req);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment