如何从存储中检索标记为字符串(string.split error)

时间:2017-07-27 22:31:15

标签: angular ionic-framework

我一直在尝试使用string.split jwtHelper获取jwtHeler.decodeToken(token).iat错误。如何将字符串检索为字符串而不是承诺?

这是我记录token

时得到的结果
t {__zone_symbol__state: null, __zone_symbol__value: Array(0)}
__zone_symbol__state:true
__zone_symbol__value:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIzMjkiLCJpc3MiOiJodHRwOlwvXC9wcm9qZWN0cy5zdGFybGluZXdpbmRvd3MuY29tXC9yZWZyZXNoIiwiaWF0IjoxNTAxMTY

刷新功能

public scheduleRefresh() {

    let source = this.authHttp.tokenStream.flatMap(
      token => {
        console.log("token=", token);
        let jwtIat = this.jwtHelper.decodeToken(token).iat;
        let jwtExp = this.jwtHelper.decodeToken(token).exp;
        let iat = new Date(0);
        let exp = new Date(0);

        let delay = (exp.setUTCSeconds(jwtExp) - iat.setUTCSeconds(jwtIat));

        return Observable.interval(delay);
      });

    this.refreshSubscription = source.subscribe(() => {
      this.refresh().subscribe((res) => console.log('-> Refreshed...'), 
      (error) => console.log('Refresh error: ' + JSON.stringify(error)))
    });
  }
}

app.module.ts

export function getAuthHttp(http, storage) {
  return new AuthHttp(new AuthConfig({
    headerName: 'Authorization',
    headerPrefix: 'Bearer',
    noJwtError: true,
    globalHeaders: [{'Accept': 'application/json', 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest'}],
    tokenGetter: (() =>   storage.ready().then(() => storage.get('token')))
  }), http);
}

0 个答案:

没有答案