jwt令牌刷​​新后重新发送失败的呼叫

时间:2020-05-22 13:45:34

标签: javascript angular jwt angular7

我对angular并不陌生,我正在尝试开发一个刷新jwt令牌模块。一切正常,但我无法重新发送失败的呼叫。

我的角度版本是7.0.2

Jwt拦截器

@Injectable()
export class JWTInterceptor implements HttpInterceptor {

constructor(public authService: AuthenticationService,
            public customConfigurationService: CustomConfirmationService,
            private toastr: ToastrService){}

intercept(req: import("@angular/common/http").HttpRequest<any>, next: import("@angular/common/http").HttpHandler): import("rxjs").Observable<import("@angular/common/http").HttpEvent<any>> {
    return next.handle(req).do((event: HttpEvent<any>) => {
        if (event instanceof HttpResponse) {
          // do stuff with response if you want
        }
      }, (err: any) => {
        if (err instanceof HttpErrorResponse) {
          if (err.status === 401) {
            this.authService.collectFailedRequest(req);
            this.customConfigurationService.askConfirmation('Info','Expired Token ', 'Update Token',
                ()=> {
                this.authService.refreshToken().subscribe(
                    (value : any) => {
                        this.authService.setToken(value.token);
                        return next.handle(req);
                    }, 
                    error => console.log("Error during refresh token") 

                    )
                }
            )
          }
        }
      });
  }
}

AuthenticationService

refreshToken() : Observable<Object> {
    let url: string = "url_to_refresh_token";
    return this.http.post(url , {
      //same parameters
    });
  }

当令牌过期或不存在时,我打开一个模式以刷新令牌,而我想重新分配上一个呼叫,但

返回next.handle(req);

似乎无法正常工作,实际上“网络”标签为空

enter image description here

对此有何建议?我在哪里做错了?

0 个答案:

没有答案