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

feat: add maxTokenLength config

上级 398771a3
...@@ -41,9 +41,12 @@ export default class TokenUtils { ...@@ -41,9 +41,12 @@ export default class TokenUtils {
tokenExpiresIn, tokenExpiresIn,
tokenExpiresThreshold tokenExpiresThreshold
} = this.config } = this.config
if (tokenExpiresThreshold > tokenExpiresIn) { if (tokenExpiresThreshold >= tokenExpiresIn) {
throw new Error('Config error, tokenExpiresThreshold should be less than 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 () { get customToken () {
...@@ -193,7 +196,8 @@ export default class TokenUtils { ...@@ -193,7 +196,8 @@ export default class TokenUtils {
const now = Date.now() const now = Date.now()
const { const {
tokenSecret, tokenSecret,
tokenExpiresIn tokenExpiresIn,
maxTokenLength = 10
} = this.config } = this.config
const token = jwt.sign({ const token = jwt.sign({
...signContent, ...signContent,
...@@ -219,6 +223,10 @@ export default class TokenUtils { ...@@ -219,6 +223,10 @@ export default class TokenUtils {
tokenList.push(token) tokenList.push(token)
if (tokenList.length > maxTokenLength) {
tokenList.splice(0, tokenList.length - 10)
}
await this.updateUserRecord({ await this.updateUserRecord({
last_login_ip: this.clientInfo.clientIP, last_login_ip: this.clientInfo.clientIP,
last_login_date: now, last_login_date: now,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册