Is it possible to check whether a id token is expired or not inside a component of angular 2 app? I got an AuthService with the method
public isAuthenticated(): boolean {
/* check if id_token is expired or not */
return tokenNotExpired();
}
Used inside the template it works fine. If a user is signed out it returns false, after the user signed in angular change detection reruns the function in the template and it returns true.
Used inside a component
@Component({
selector: 'app',
providers: [
Auth
],
templateUrl: 'app.template.html'
})
export class AppComponent implements OnInit {
public isAuthorized: Object = {};
constructor(private auth: Auth) {
this.auth.handleAuthentication();
}
ngOnInit() {
console.log(this.auth.isAuthenticated());
}
}
it does not get updated after the user signed in. A page refresh is needed. How could I solve this?