2016-10-04 80 views
1

我正在关注此angular2-authentication-sample进行身份验证。我不希望客户端jwt_dcode和jwt_encode在项目中都被删除。但我仍然得到错误在此文件home.ts(24,42): error TS2339: Property 'jwt_decode' does not exist on type 'Window'.(24,42):错误TS2339:属性'jwt_decode'在类型'窗口'上不存在

home.ts

import { Component } from '@angular/core'; 
import { CORE_DIRECTIVES } from '@angular/common'; 
import { Router } from '@angular/router'; 

const styles = require('./home.css'); 
const template = require('./home.html'); 

@Component({ 
    selector: 'home', 
    directives: [ CORE_DIRECTIVES ], 
    template: template, 
    styles: [ styles ] 
}) 

export class Home { } 
+0

? – micronyks

+0

@micronyks我正在使用angular2 js。这是包文件https://github.com/auth0-blog/angular2-authentication-sample/blob/master/package.json –

回答

2

我有同样的问题,并最终使用JwtHelper类。

导入:

import { AuthHttp, JwtHelper } from 'angular2-jwt'; 

实例化:

jwtHelper: JwtHelper = new JwtHelper(); 

用途:

constructor() { 
    this.token = localStorage.getItem('id_token'); 

    // this.decodedJwt = this.jwt && window.jwt_decode(this.jwt); 

    this.decodedJwt = this.jwtHelper.decodeToken(this.token); 
    this.jwtDate = this.jwtHelper.getTokenExpirationDate(this.token); 
    this.jwtExpired = this.jwtHelper.isTokenExpired(this.token); 
} 
您使用angular2的版本
+0

我不希望编码和解码发生在客户端。我不想使用任何助手。 –

相关问题