question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

isTokenExpired how To? (something like tokenNotExpired for 1.x branch)

See original GitHub issue

Howe to check if token is Expired with 1.x branch as tokenNotExpired?

what’s wrong?

this code return many exception because it can’t get the token or token is not valid.

import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/delay';
import { JwtHelperService } from '@auth0/angular-jwt';


@Injectable()
export class AuthService {

  // store the URL so we can redirect after logging in
  redirectUrl: string;


  constructor(private jwtHelper: JwtHelperService) {
  }

  isLoggedIn() {
    return this.jwtHelper.isTokenExpired();
  }

  login(): Observable<boolean> {
    return Observable.of(true).delay(1000).do(val => true);
  }

  logout(): void {

  }


}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

14reactions
gimoxcommented, Oct 5, 2017

I found a solution.


import {JwtHelperService} from '@auth0/angular-jwt';
...

 tokenNotExpired() {
    const token: string = this.tokenService.get();

    return token != null && !this.jwtHelper.isTokenExpired(token);
  }


3reactions
hs950559commented, Mar 4, 2018

Thanks @gimox this is what i was looking.

isLoggedin() { const token: string = localStorage.getItem(‘token’); return token != null && !this.jwtHelper.isTokenExpired(token); }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular6 auth0/angular2-jwt isTokenExpired function always ...
You should use { tokenNotExpired } 'angular2-jwt'; You will need following implementation: Inside your app.module.ts
Read more >
angular/angular - Gitter
preloadFx$(game):Observable<number> { const loadAudio$ = this.fx.add(game.words.map(x=>x.audio)); const loadImages$ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found