2016-10-04 22 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'がタイプ 'Window'に存在しません

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(); 

用途:あなたはangular2で使用しているバージョン

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); 
} 
+0

私はエンコードとデコードがクライアント側で行われることは望ましくありません。私はどんなヘルパーも使いたくない。 –

関連する問題