Dear All,
I have this specific code that I have to include in each component before transitioning to each page. Basically I need to check whether the JWT has expired or not.
let isTokenExp = this.jwtHelper.isTokenExpired(data);
if (isTokenExp) {
let alert = this.alertCtrl.create({
title: 'Warning',
subTitle: 'Your session has been expired. You will be logged out.',
buttons: ['Ok']
})
alert.present();
alert.onDidDismiss(() => {
//clear token
this.authTokenService.deleteToken().then(() => {
this.navCtrl.setRoot('LoginPage');
}).catch((err) => {
//alert error to user.
this.navCtrl.setRoot('LoginPage');
})
})
}
Would want a way to write it once and use it everywhere? Please advise.
Thanks,
Ashley