jwt.js (675B)
1 2 function isJwtValid() { 3 const jwt = getJwt(); 4 if (jwt == null) { 5 return; 6 } 7 8 const jwtBody = getJwtBody(jwt); 9 const expirationInMilliseconds = jwtBody.exp * 1000; 10 11 return expirationInMilliseconds * 1000 > Date.now(); 12 } 13 14 function decodeJwt(token) { 15 if (token == null) { 16 return; 17 } 18 19 const res = []; 20 const splitToken = token.split("."); 21 22 // We only want the first two parts of the token decoded 23 res.push(JSON.parse(atob(splitToken[0]))); 24 res.push(JSON.parse(atob(splitToken[1]))); 25 26 return res; 27 } 28 29 function getJwtBody(token) { 30 if (token == null) { 31 return; 32 } 33 34 return decodeJwt(token)[1]; 35 }