V0.29.1.250619_alpha:修复认证过期时间异常的问题
This commit is contained in:
parent
19147adc1b
commit
10cef47e42
Binary file not shown.
@ -293,13 +293,26 @@
|
||||
});
|
||||
document.dispatchEvent(loginSuccessEvent);
|
||||
} else {
|
||||
authContainer.classList.add('visible');
|
||||
mainContainer.classList.remove('visible');
|
||||
// 只有在非定时检查时才显示登录界面,避免频繁切换
|
||||
if (!isInterval) {
|
||||
authContainer.classList.add('visible');
|
||||
mainContainer.classList.remove('visible');
|
||||
} else {
|
||||
// 定时检查发现未登录,显示提示并跳转到登录页面
|
||||
showToast('登录已过期,请重新登录');
|
||||
setTimeout(() => {
|
||||
authContainer.classList.add('visible');
|
||||
mainContainer.classList.remove('visible');
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('认证检查错误:', error);
|
||||
authContainer.classList.add('visible');
|
||||
mainContainer.classList.remove('visible');
|
||||
// 只有在非定时检查时才显示登录界面
|
||||
if (!isInterval) {
|
||||
authContainer.classList.add('visible');
|
||||
mainContainer.classList.remove('visible');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -711,10 +724,29 @@
|
||||
// 初始检查认证状态
|
||||
checkAuth();
|
||||
|
||||
// 每5分钟检查一次认证状态
|
||||
// 用户活动检测 - 当用户有活动时主动更新 session
|
||||
let userActivityTimeout;
|
||||
const resetUserActivity = () => {
|
||||
clearTimeout(userActivityTimeout);
|
||||
userActivityTimeout = setTimeout(() => {
|
||||
// 用户无活动超过10分钟时,进行一次认证检查
|
||||
checkAuth(true);
|
||||
}, 10 * 60 * 1000); // 10分钟无活动后检查
|
||||
};
|
||||
|
||||
// 监听用户活动事件
|
||||
const userActivityEvents = ['mousedown', 'mousemove', 'keypress', 'scroll', 'touchstart', 'click'];
|
||||
userActivityEvents.forEach(event => {
|
||||
document.addEventListener(event, resetUserActivity, true);
|
||||
});
|
||||
|
||||
// 每10分钟检查一次认证状态(减少检查频率,因为有了用户活动检测)
|
||||
setInterval(() => {
|
||||
checkAuth(true); // 传true表示定时检查
|
||||
}, 5 * 60 * 1000); // 5分钟
|
||||
}, 10 * 60 * 1000); // 10分钟
|
||||
|
||||
// 初始化用户活动检测
|
||||
resetUserActivity();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
@ -50,6 +50,7 @@ app.use(session({
|
||||
secret: 'xnsim-secret-key', // 用于签名 session ID cookie 的密钥
|
||||
resave: false, // 不强制保存 session
|
||||
saveUninitialized: false, // 不强制将未初始化的 session 存储
|
||||
rolling: true, // 每次请求时重置 cookie 的过期时间
|
||||
cookie: {
|
||||
httpOnly: true, // 防止客户端 JavaScript 访问 cookie
|
||||
secure: process.env.NODE_ENV === 'production', // 在生产环境使用 HTTPS
|
||||
|
Loading…
x
Reference in New Issue
Block a user