Facing issue to handle observable with jquery and angular

戏子无情 提交于 2019-12-11 15:51:49

问题


I have requirement where I need to use jquery dataTables in angular 5 application. I am facing issue to refresh the token. Below is the code that I am using to achive this:

sendRequest() {
    const requestObject = {
        'url': '/getUsers',
        'type': 'GET',
        'beforeSend': self.refreshToken(),
        'error': function (xhr, error, thrown) {
                  if(xhr.status === 401) {
                  return self.refreshToken().concatMap(()  => {
                      self.sendRequest();
                    })
                  }
                }
}

And below is my code to refresh the token:

refreshToken(req, next) {
    const headers = new HttpHeaders()
        .set('Content-Type', 'application/x-www-form-urlencoded');

    const body = new HttpParams()
      .set('refresh_token', localStorage.getItem('refreshToken'));
     this._http.post('/refreshtoken',  body.toString(), {headers}).do(
       (data) => {
         const header = `Bearer ${(<any>data).accessToken}`;
        const newRequest = req.clone({ headers: req.headers.set('Authorization',  header)});
        return next.handle(newRequest);
       })

  }

But using above approach I am never able to call refresh token request. Please let me know what I am missing here. I am thinking that do function is not calling here.

来源:https://stackoverflow.com/questions/48887271/facing-issue-to-handle-observable-with-jquery-and-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!