提交 75fe442e 编写于 作者: 雪洛's avatar 雪洛

feat: add maxTokenLength config

上级 398771a3
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册