From 91a4e06cb724d6a4082b0bdb22ff8879b4333635 Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 28 Jan 2021 17:55:26 -0800 Subject: [PATCH] moving jwt and login related things to new auth module --- freechat-client/src/auth.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 freechat-client/src/auth.js diff --git a/freechat-client/src/auth.js b/freechat-client/src/auth.js new file mode 100644 index 0000000..38fee50 --- /dev/null +++ b/freechat-client/src/auth.js @@ -0,0 +1,17 @@ +const jsonwebtoken = require('jsonwebtoken') + +/** + * Checks to see if the jwt is not expired basically + * + * @param {String} jwt token string to verify + * @returns Boolean + */ +exports.valid_jwt = function (jwt) { + const result = jsonwebtoken.decode(jwt) + if(result) { + const now = Math.floor(Date.now() / 1000) + return result['exp'] > now // does it expire later? + } else { + return false; + } +}