Reputation: 1065
I'm trying to add duration
for each token. For now each token has duration 3600000ms(1hour), and maybe it will change base on term and conditions.
I create the duration using this:
global.duration = 60*60*1000;
and I also have a column called createdAt, default from sequelize. With format
Monday, August 5, 2019 3:22:57 AM +00:00
for each activity with method POST, there will be a token duration checking first. The logic for checking is if the total = duration + createdAt
is less than currenttime
, the request is permitted, if not the user will be ask for re-login.
I don't know how to start, i'm confused because the duration is in millisecond, and the createdAt is in dateTime. I dont know how to total both of them.
Upvotes: 2
Views: 134
Reputation: 488
I guess this is what you are looking for
let curTime = new Date().getTime();
let createdAt = "Mon Aug 05 2019 10:00:12 GMT+0530 (India Standard Time)";
let createdAtTime = new Date(createdAt).getTime();
let duration = 60 * 60 * 1000;
let expiryTime = createdAtTime + duration;
if (curTime < expiryTime) {
console.log("Token is valid.");
} else {
console.log("Token has expired.");
}
Upvotes: 1