Hi @carson.zoom many thanks your help, but I trying your suggestion and I changed my code for this mode:
const jwt = require("jsonwebtoken");
const getIatExp = (dt, minutes) => {
return {
iat: new Date(dt.getTime()).getTime(),
exp: new Date(dt.getTime() + minutes * 60000).getTime(),
};
};
const getTokenExpire = (iat, minutes) => {
return {
tokenExp: new Date(iat + minutes * 60000).getTime(),
};
};
const { iat, exp } = getIatExp(new Date(), 30);
const { tokenExp } = getTokenExpire(iat, 60);
const payloadSDK = {
appKey: "",
iat: iat,
exp: exp,
tokenExp: tokenExp,
};
const tokenSDK = jwt.sign(payloadSDK, "");
console.log("\n********* TOKEN ********* \n");
console.log(tokenSDK);
console.log("\n************************* \n");
console.log("\n********* DEBUG ********* \n");
console.log("iat:", new Date(iat).toString());
console.log("exp:", new Date(exp).toString());
console.log("tokenExp:", new Date(tokenExp).toString());
console.log("\n************************* \n");
console.log("\n********* DEBUG PAYLOAD ********* \n");
console.log(payloadSDK);
console.log("\n************************* \n");
console.log("\n********* DEBUG PAYLOAD TO STRING ********* \n");
const debugPayloadSDK = {
appKey: "",
iat: new Date(iat).toString(),
exp: new Date(exp).toString(),
tokenExp: new Date(tokenExp).toString(),
};
console.log(debugPayloadSDK);
console.log("\n************************* \n");
But I continue received the same error.
My output console log:
********* TOKEN *********
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBLZXkiOiJ5V0lVcVdnT2M2QnRUQjlFblBJOVNUWHc1anpsQVpTNUo0bUUiLCJpYXQiOjE1OTU2MDcxOTEyNzYsImV4cCI6MTU5NTYwODk5MTI3NiwidG9rZW5FeHAiOjE1OTU2MTA3OTEyNzZ9.R0Q7-lKIjjJdaTh_sj4uYuL9VoiPZ4CbMtdqIdgAGYI
*************************
********* DEBUG *********
iat: Fri Jul 24 2020 13:13:11 GMT-0300 (Brasilia Standard Time)
exp: Fri Jul 24 2020 13:43:11 GMT-0300 (Brasilia Standard Time)
tokenExp: Fri Jul 24 2020 14:13:11 GMT-0300 (Brasilia Standard Time)
*************************
********* DEBUG PAYLOAD *********
{ appKey: '',
iat: 1595607191276,
exp: 1595608991276,
tokenExp: 1595610791276 }
*************************
******* DEBUG PAYLOAD TO STRING *******
{ appKey: '',
iat: 'Fri Jul 24 2020 13:13:11 GMT-0300 (Brasilia Standard Time)',
exp: 'Fri Jul 24 2020 13:43:11 GMT-0300 (Brasilia Standard Time)',
tokenExp: 'Fri Jul 24 2020 14:13:11 GMT-0300 (Brasilia Standard Time)' }
*************************
In:
const { tokenExp } = getTokenExpire(iat, 60);
I tried this mode too:
const { tokenExp } = getTokenExpire(iat, 30);
But I continue received the same error code 5.