Skip to content

Instantly share code, notes, and snippets.

@prestigegodson
Created May 4, 2019 12:59
Show Gist options
  • Save prestigegodson/79f76369f08301f16d2a656a23f69ee5 to your computer and use it in GitHub Desktop.
Save prestigegodson/79f76369f08301f16d2a656a23f69ee5 to your computer and use it in GitHub Desktop.
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>,
next: HttpHandler): Observable<HttpEvent<any>> {
const idToken = localStorage.getItem("id_token");
if (idToken) {
const cloned = req.clone({
headers: req.headers.set("Authorization",
"Bearer " + idToken)
});
return next.handle(cloned);
}
else {
return next.handle(req);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment