Jwt 在代币发行日期后增加8小时
我有这个功能:Jwt 在代币发行日期后增加8小时,jwt,token,access-token,Jwt,Token,Access Token,我有这个功能: export const isTokenValid = () => { const isTokenExist = localStorage.getItem("TOKEN_AUTH"); if (!isTokenExist) return false; const token = isTokenExist.split(" ")[1]; const jwt = JSON.parse(atob(token.split(".")[1])); const iat
export const isTokenValid = () => {
const isTokenExist = localStorage.getItem("TOKEN_AUTH");
if (!isTokenExist) return false;
const token = isTokenExist.split(" ")[1];
const jwt = JSON.parse(atob(token.split(".")[1]));
const iat = (jwt && jwt.iat * 1000) || null;
console.log(iat);
console.log(Date.now());
const isExp = Date.now() > iat;
if (isExp) {
// localStorage.clear();
return false;
}
return true;
};
在console.log()中:
我必须检查代币是否有效,从(iat)+8小时到现在。如何将8小时添加到iat值。JWT中的时间戳是UNIX时间戳,从1970年1月1日00:00 UTC开始计数:说明exp索赔(以及nbf(非之前)和iat(发布于)索赔)使用数字日期 定义数字日期: 一个JSON数值,表示从 1970-01-01T00:00:00Z UTC,直到指定的UTC日期/时间,忽略 闰秒 3600秒是一小时,因此您将从令牌(1516239022)中向原始iat值添加8*3600=28.800。 但是,正如您的代码所示,没有必要乘以1000
1516239022000
1585764070793