1
我有一個認證攔截器,但是,我希望當用戶訪問像確認賬號密碼等,這並不需要用戶身份驗證的組件這個攔截過濾請求並沒有被應用。如何去做任何的例子嗎?以下是auth攔截器的邏輯:過濾請求 - 角4.3+
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Get the auth token from the service.
let authToken = this.authService.getToken();
let authHeader = 'Bearer ' + authToken;
//For requests that are retried, we always want a fresh copy, else the request will have headers added multiple times.
//So Clone the request before adding the new header.
//NOTE: the cache and pragma are required for IE that will otherwise cache all get 200 requests.
const authReq = request.clone({
setHeaders: {
Authorization: authHeader,
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
}
});
// Pass on the cloned request instead of the original request.
return next.handle(authReq);
}