I wrote a custom token authenticator and I have used local storage.
Code Explanation: In restore method, if token is not empty and if expiresAt is greater than current time I have calculated the wait time and set invalidate method to be executed after calculated wait time using ember.run.later.
Problem: It seems ember.run.later is not working. Even after expiration time the token persist in local storage. so that i can send request and response even after expiration time. Only after refreshing the page, the token get destroyed in local storage and redirects to login page.
but expected behavior is, the token should be automatically destroyed in local storage after expiration time (without page reload) and redirects to login page.
As a beginner I may misunderstood the concepts. So correct me if I was wrong.
authenticators/custom.js
restore(data) {
let token, tokenData;
const dataObject = Ember.Object.create(data);
return new Ember.RSVP.Promise((resolve, reject) => {
const now = Math.floor((new Date()).getTime() / 1000);
token = dataObject.get('token');
if (Ember.isEmpty(token)) {
reject();
}
else {
tokenData = this.getTokenData(token);
const expiresAt = tokenData['exp'];
if (expiresAt > now) {
const wait = ( expiresAt - now ) * 1000;
Ember.run.later(this, this.invalidate(data), wait);//not working
resolve(data);
}
else {
reject();
}
}
});
}
Aucun commentaire:
Enregistrer un commentaire