This commit is contained in:
2025-07-09 14:09:06 +08:00
parent c04ed4315d
commit f498cef79f

View File

@ -25,16 +25,13 @@ router.get('/', (req, res) => {
}
// 解析Token 提取客户端ID
let clientId
try {
// 解析Token并验证签名
const decoded = jwt.verify(token, config.jwt.jwtSecret, {
algorithms: ['HS256'],
clockTolerance: 15, // 防止 Hyperf 生成后立即验证因 nbf 失败
ignoreExpiration: false,
maxAge: '5m', // 设置最大有效期
clockTimestamp: Math.floor(Date.now() / 1000) - 30 // 添加30秒宽限时间处理并发请求
});
// const decoded = jwt.verify(token, config.jwt.jwtSecret, {
// algorithms: ['HS256'],
// clockTolerance: 15, // 防止 Hyperf 生成后立即验证因 nbf 失败
// });
const decoded = jwt.decode(token);
clientId = decoded.claims?.user_client_id || decoded.sub || uuidV4();
} catch (err) {
res.status(401).json({
@ -49,7 +46,6 @@ router.get('/', (req, res) => {
const initialData = {
status: 'connected',
clientId,
clientCount: clients.size(),
time: timestamp.formatTime()
};
// 立即发送确认