Reputation: 3481
I'm following this angular2-authentication-sample for authentication. I don't want the client side jwt_dcode and jwt_encode removed the both in the project. But still i get the error in this file home.ts
(24,42): error TS2339: Property 'jwt_decode' does not exist on type 'Window'.
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 { }
Upvotes: 1
Views: 2884
Reputation: 1029
I had the same issue and ended up using the JwtHelper class.
Import:
import { AuthHttp, JwtHelper } from 'angular2-jwt';
Instantiate:
jwtHelper: JwtHelper = new JwtHelper();
Use:
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);
}
Upvotes: 2