mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
adjusted
This commit is contained in:
+14
-1
@@ -67,4 +67,17 @@ const verifyRefreshToken = (token) =>
|
||||
const hashToken = (token) =>
|
||||
crypto.createHash('sha256').update(token).digest('hex');
|
||||
|
||||
module.exports = { generateTokens, verifyAccessToken, verifyRefreshToken, hashToken };
|
||||
/**
|
||||
* SHA-256 hash a token string for safe DB storage.
|
||||
* @param {string} decoded
|
||||
* @param {number} thresholdDays
|
||||
* @returns {string} if expired or not
|
||||
*/
|
||||
const shouldRotateRefreshToken = (decoded, thresholdDays = 1) => {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const timeLeft = decoded.exp - now;
|
||||
const threshold = thresholdDays * 24 * 60 * 60;
|
||||
return timeLeft <= threshold;
|
||||
};
|
||||
|
||||
module.exports = { generateTokens, verifyAccessToken, verifyRefreshToken, hashToken, shouldRotateRefreshToken };
|
||||
Reference in New Issue
Block a user