2
votes
import { tokenNotExpired } from 'angular2-jwt';

Error:

ERROR in node_modules/angular2-jwt/angular2-jwt.d.ts(3,10): error TS2305: Module '"C:/Users/Charles Edwin Ison/OOP/node_modules/rxjs/Observable"' has no exported member 'Observable'. node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.

How to fix this?

3

3 Answers

0
votes

I resolved this issue using @auth0/angular-jwt with angular 6. You first need to uninstall angular2-jwt completely:

npm uninstall angular2-jwt --save

Then you can run:

npm install @auth0/angular-jwt

Only these two command lines helped me.

0
votes

If you re using Angular 4.3 or above you don't have support with old version of angular2-jwt. if you use older version you will get more errors since it relies on an Http Interceptor from Angular's HttpClient.what you can do is download the new version @auth0/angular-jwt and implement method for tokenNotExpired

# installation with npm
npm install @auth0/angular-jwt

simply you can implement in this way

export function tokenGetter(access_token : string) {
  return localStorage.getItem(access_token);
}

private tokenNotExpired(token : string)
{
  const item: string = tokenGetter(token);
  return item != null && !this.jwtHelper.isTokenExpired(item);
}
0
votes
npm uninstall angular2-jwt
npm install @auth0/angular-jwt
npm install rxjs-compat --save

In auth.service.ts:

import { JwtHelperService } from "@auth0/angular-jwt";
 token: string

  isAuthenticated() {
return this.jwtHelper.isTokenExpired(this.token);

}

in header.component.html:

 <a class="nav-link" [routerLink]="['/dashboard']" routerLinkActive="active-link"
       *ngIf="!authService.isAuthenticated()"
       [routerLinkActiveOptions]="{exact: true}">Dashboard</a>
    <a class="btn btn-outline-primary me-2"  *ngIf="authService.isAuthenticated()"
       [routerLink]="['/auth']" tabindex="-1" aria-disabled="true">Sign in</a>