MCPcopy Create free account
hub / github.com/Rfym21/Qwen2API / validateToken

Method validateToken

src/utils/token-manager.js:75–94  ·  view source on GitHub ↗

* 验证令牌是否有效 * @param {string} token - JWT令牌 * @returns {Object|null} 解码后的令牌信息或null

(token)

Source from the content-addressed store, hash-verified

73
74 /**
75 * 验证令牌是否有效
76 * @param {string} token - JWT令牌
77 * @returns {Object|null} 解码后的令牌信息或null
78 */
79 validateToken(token) {
80 try {
81 if (!token) return null
82
83 const decoded = JwtDecode(token)
84 if (!decoded || !decoded.exp) {
85 return null
86 }
87
88 const now = Math.floor(Date.now() / 1000)
89 if (decoded.exp <= now) {
90 return null // 令牌已过期
91 }
92
93 return decoded
94 } catch (error) {
95 logger.error('令牌验证失败', 'TOKEN', '', error)
96 return null
97 }

Callers 7

isTokenExpiringSoonMethod · 0.95
refreshTokenMethod · 0.95
getTokenHealthStatsMethod · 0.95
addAccountMethod · 0.80

Calls 2

JwtDecodeFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected