diff --git a/src/lib/token/token-utils.js b/src/lib/token/token-utils.js index 6ac4c29ef49d53dc39414c98ba38e9ec66a43f74..8e461112898ddd6a2c3afe1125361e804157d571 100644 --- a/src/lib/token/token-utils.js +++ b/src/lib/token/token-utils.js @@ -41,9 +41,12 @@ export default class TokenUtils { tokenExpiresIn, tokenExpiresThreshold } = this.config - if (tokenExpiresThreshold > tokenExpiresIn) { + if (tokenExpiresThreshold >= tokenExpiresIn) { throw new Error('Config error, tokenExpiresThreshold should be less than tokenExpiresIn') } + if (tokenExpiresThreshold > tokenExpiresIn / 2) { + console.warn(`Please check whether the tokenExpiresThreshold configuration is set too large, tokenExpiresThreshold: ${tokenExpiresThreshold}, tokenExpiresIn: ${tokenExpiresIn}`) + } } get customToken () { @@ -193,7 +196,8 @@ export default class TokenUtils { const now = Date.now() const { tokenSecret, - tokenExpiresIn + tokenExpiresIn, + maxTokenLength = 10 } = this.config const token = jwt.sign({ ...signContent, @@ -219,6 +223,10 @@ export default class TokenUtils { tokenList.push(token) + if (tokenList.length > maxTokenLength) { + tokenList.splice(0, tokenList.length - 10) + } + await this.updateUserRecord({ last_login_ip: this.clientInfo.clientIP, last_login_date: now,