xxxxxxxxxx
// Set the current JWT token
let token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzZGIzZjZmMDYwY2M4NWI5NzkzZjk2ZSIsImVtYWlsIjoiYXZ3ZWJ0ZXN0QGdtYWlsLmNvbSIsImlhdCI6MTY3ODk0OTM0MywiZXhwIjoxNjc5NTU0MTQzfQ.rp_cjZY5At-wuxE2wupu1i402s3__MQx54lXsQ63rHU";
const jwt = require("jsonwebtoken");
// Set the expiration time to a timestamp in the past
const expiredToken = jwt.sign({}, "karbon_secret", { expiresIn: 0 });
// Extract the payload from the expired token
const payload = jwt.decode(token);
// Extract the header from the original token
const header = jwt.decode(token, { complete: true }).header;
// Sign the payload with the same header and secret as the original token
// const newToken = jwt.sign(payload, 'your_secret_key', { header });
// Log the expired token and the new token to the console
console.log("Expired token:", expiredToken);
// console.log('New token:', newToken);
xxxxxxxxxx
var token = jwt.sign({email_id:'123@gmail.com'}, "Stack", {
expiresIn: "10h" // it will be expired after 10 hours
//expiresIn: "20d" // it will be expired after 20 days
//expiresIn: 120 // it will be expired after 120ms
//expiresIn: "120s" // it will be expired after 120s
});
xxxxxxxxxx
var token = jwt.sign({email_id:'123@gmail.com'}, "Stack", {
expiresIn: '24h' // expires in 24 hours
});
xxxxxxxxxx
const options = {expires: new Date(Date.now() + 90*24*60*60*1000) , httpOnly : true};
res.status(200).cookie("token", token , options).json({ sucess: true, user, token });
// you can use time like this 90(days)*24(hours)*60(minute)*60(second)*1000(miliseconds)