Skip to content

Commit 351f4a1

Browse files
author
pedro
committed
fix:修复token的过期日期
1 parent 52035ed commit 351f4a1

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

lib/jwt.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import { config } from "./config";
1414

1515
export class Token {
1616
private secret: string | undefined;
17-
private accessExp: number = Math.floor(Date.now() / 1000) + 60 * 60; // 1h;
18-
private refreshExp: number =
19-
Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 30 * 3; // 3 months
17+
private accessExp: number = 60 * 60; // 1h;
18+
private refreshExp: number = 60 * 60 * 24 * 30 * 3; // 3 months
2019

2120
constructor(secret?: string, accessExp?: number, refreshExp?: number) {
2221
secret && (this.secret = secret);
@@ -48,9 +47,10 @@ export class Token {
4847
if (!this.secret) {
4948
throw new Error("密匙不可为空");
5049
}
50+
let exp: number = Math.floor(Date.now() / 1000) + this.accessExp;
5151
return jwtGenerator.sign(
5252
{
53-
exp: this.accessExp,
53+
exp: exp,
5454
identity: identity,
5555
type: TokenType.ACCESS
5656
},
@@ -66,9 +66,10 @@ export class Token {
6666
if (!this.secret) {
6767
throw new Error("密匙不可为空");
6868
}
69+
let exp: number = Math.floor(Date.now() / 1000) + this.refreshExp;
6970
return jwtGenerator.sign(
7071
{
71-
exp: this.refreshExp,
72+
exp: exp,
7273
identity: identity,
7374
type: TokenType.REFRESH
7475
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lin-cms",
3-
"version": "0.0.1-alpha5",
3+
"version": "0.0.1-alpha6",
44
"description": "The core library of Lin CMS, this package is just for test!",
55
"main": "lin/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)