Skip to content

Commit ada794a

Browse files
committed
feat: update token expiration logic to refresh 120 minutes before expiration in AdminAccessControl and UserAccessControl.
Signed-off-by: leozhang2018 <leozhang2018@gmail.com>
1 parent 0e0c797 commit ada794a

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/AdminAccessControl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ async function getToken(code: string): Promise<boolean> {
5151
}
5252

5353
/**
54-
* 检查Token是否即将过期(提前5分钟刷新
54+
* 检查Token是否即将过期(提前 120 分钟刷新
5555
* @param expireTime Token过期时间戳(毫秒)
5656
* @returns 是否即将过期
5757
*/
5858
function isTokenExpiringSoon(expireTime: number): boolean {
59-
const fiveMinutesInMs = 5 * 60 * 1000; // 5分钟
60-
return (expireTime - Date.now()) < fiveMinutesInMs;
59+
const timeLeft = 120 * 60 * 1000; // 120分钟
60+
return (expireTime - Date.now()) < timeLeft;
6161
}
6262

6363
/**

src/UserAccessControl.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ async function getToken(code: string): Promise<boolean> {
5151
}
5252

5353
/**
54-
* 检查Token是否即将过期(提前5分钟刷新
54+
* 检查Token是否即将过期(提前 120 分钟刷新
5555
* @param expireTime Token过期时间戳(毫秒)
5656
* @returns 是否即将过期
5757
*/
5858
function isTokenExpiringSoon(expireTime: number): boolean {
59-
const fiveMinutesInMs = 5 * 60 * 1000; // 5分钟
60-
return (expireTime - Date.now()) < fiveMinutesInMs;
59+
const timeLeft = 120 * 60 * 1000; // 120分钟
60+
return (expireTime - Date.now()) < timeLeft;
6161
}
6262

6363
/**
@@ -79,6 +79,8 @@ async function checkLogin(checkExpiringSoon: boolean = false): Promise<boolean>
7979
if (!plugin_access_token || !plugin_access_token_expire_time || !user_access_token || !user_access_token_expire_time) {
8080
return false;
8181
}
82+
console.log(pluginLocalAuth)
83+
8284

8385
// 检查是否已过期(expire_time 已经是毫秒级时间戳)
8486
const pluginTokenExpired = plugin_access_token_expire_time <= Date.now();
@@ -93,6 +95,7 @@ async function checkLogin(checkExpiringSoon: boolean = false): Promise<boolean>
9395
const userTokenExpiringSoon = isTokenExpiringSoon(user_access_token_expire_time);
9496

9597
if (pluginTokenExpiringSoon || userTokenExpiringSoon) {
98+
console.log('checkExpiringSoon', checkExpiringSoon)
9699
return false;
97100
}
98101
}

0 commit comments

Comments
 (0)